how to create Singleinstance application
-
wrote on 11 Jan 2019, 10:58 last edited by
hi,,,
if im running exe file its opening application again if i click exe file it is opening new application ,,,
i want only one application if it is already opened it should show Qmessaageboxplease help me,,,,
thanks in advance -
hi,,,
if im running exe file its opening application again if i click exe file it is opening new application ,,,
i want only one application if it is already opened it should show Qmessaageboxplease help me,,,,
thanks in advancewrote on 11 Jan 2019, 11:02 last edited by Ratzz 1 Nov 2019, 11:12@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/ -
hi,,,
if im running exe file its opening application again if i click exe file it is opening new application ,,,
i want only one application if it is already opened it should show Qmessaageboxplease help me,,,,
thanks in advance@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); }
-
@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/wrote on 11 Jan 2019, 11:11 last edited by@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> -
@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>wrote on 11 Jan 2019, 11:17 last edited by Ratzz 1 Nov 2019, 11:20@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 . -
@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); }
wrote on 11 Jan 2019, 11:25 last edited by@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
-
@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.
-
@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 .wrote on 11 Jan 2019, 12:12 last edited by@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
-
@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
wrote on 11 Jan 2019, 12:18 last edited by@Bharth said in how to create Singleinstance application:
i dont know which i should add to my project
-
wrote on 12 Jan 2019, 05:39 last edited by
thanks for your reply ,,,i will try
-
wrote on 14 Jan 2019, 10:28 last edited by
its working but not able to show qmessagebox,,,,
again if i click exe file it should open old one now its not opening -
its working but not able to show qmessagebox,,,,
again if i click exe file it should open old one now its not opening@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; }
-
wrote on 14 Jan 2019, 13:25 last edited by
@jsulm said in how to create Singleinstance application:
QMessageBox::information(nullptr, "Information", "Already running!", ...);
thank you so much its worked....
1/13