You can use shared memory to solve your problem. I used this approach so as not to run another instance of my program while there is already an instance running. In fact, I implemented this to achieve the so-called single-instance application.
However, your case is slightly different from mine, you need to somehow send a signal from the second application to the first in order to close it. I think you can achieve this behavior using QSharedMemory.
, , - (UUID) , , , , , .
, . , , ( qt) , , () , . , , , , ...
:
IN MAIN
check if shared memory in use
if yes
fire the exit function via shared memory to close 1st app
if no
put the function pointer which will close the app when another instance come up
do stuff
,
QSharedMemory shared(AppConstants::UUID);
int main(){
if( !shared.create( 512, QSharedMemory::ReadWrite) )
{
QMessageBox::critical(0, QObject::tr("App is already running!"), QObject::tr("App is already running!"), QMessageBox::Ok, QMessageBox::Ok);
qCritical() << "Cevirgec is already running!";
exit(0);
}
else {
qDebug() << "App staring...";
}
}
;)
EDIT:
Qt-, (, ), , ( ) 1, .
! , , , . , . : QPair<int, QDateTime>