how to create Singleinstance application
-
@Bharth
You can make use ofQtSingleApplication
https://doc.qt.io/archives/qtextended4.4/qtopiadesktop/qtsingleapplication.html
How to use them here.
Good example by usingQLockFile
http://blog.aeguana.com/2015/10/15/how-to-run-a-single-app-instance-in-qt/ -
@Bharth
I do this via a QSharedMemory instance, I'm not sure if thats the best way to do it though.//insice main.cpp QSharedMemory _singular("myAppNameInstance"); if(_singular.attach(QSharedMemory::ReadOnly)){ //Instance Already running _singular.detach(); //Your MessageBox-code should go here return -42; }else{ //Program is not yet running. _singular.create(1); }
-
@Ratzz said in how to create Singleinstance application:
@Bharth
You can make use ofQtSingleApplication
https://doc.qt.io/archives/qtextended4.4/qtopiadesktop/qtsingleapplication.html
How to use them here.i checked this one it is showing file not found
#include<QtSingleApplication> -
@J.Hilk said in how to create Singleinstance application:
myAppNameInstance
QMessageBox::information(this,"Application is already running...","appname");
this keyword showing error,,,,invalid use of this
why you are retunring -42 what is the meaning...
thanks for your reply
-
@Bharth
the main.cpp is not QObject based class, so you can't give QMessageBox this as parent.why you are retunring -42 what is the meanin
The Answer to the Ultimate Question of Death, The Universe, and Everything ...
The boring answer: an arbitrary return value I choose to identify the exit of the application.
-
@Ratzz said in how to create Singleinstance application:
@Bharth said in how to create Singleinstance application:
it is showing file not found
Its not part of Qt. You need to download and add them to your project.
You can download from here .i downloaded but i dont know which i should add to my project
-
@Bharth said in how to create Singleinstance application:
again if i click exe file it should open old one now its not opening
Do you mean you want to show a message if you try to start a second instance?
Then simply do it inside this block:if (instance.sendMessage("Wake up!")) { QMessageBox::information(nullptr, "Information", "Already running!", ...); return 0; }