Check if application is running
-
wrote on 31 Jan 2014, 09:40 last edited by
Hi all,
I have 2 Qt applications: App1 and App2.
I want App1 to check if App2 is running and start it.What should be the best way to check a running Qt application?
Thanks
-
wrote on 31 Jan 2014, 09:58 last edited by
Qt has a range IPC solutions available check the following:
- "Inter-Process Communication in Qt":http://qt-project.org/doc/qt-4.8/ipc.html
- "QtSingleApplication":http://doc.qt.digia.com/solutions/4/qtsingleapplication/qtsingleapplication.html
The first is a reference to all the standard ways of communicating between two programs (QLocalServer/Socket being the easiest and most portable IMHO). The second is a special subclass of the QApplication that only allows a single instance of the application to be running at one time and therefore makes it easy to get a handle to that instance.
Hope this helps ;o)
-
wrote on 31 Jan 2014, 11:06 last edited by
... or better use "QSystemSemaphore":http://qt-project.org/doc/qt-5/qsystemsemaphore.html
QSystemSemaphore can be accessed from multiple processes
-
wrote on 31 Jan 2014, 14:25 last edited by
QtSingleApplication won't be a solution, as you're looking for two separate applications. QtSingleApplication is aimed at preventing two instances of the same application running.
The link to the IPC and the QSystemSemaphore are useful tips though :)
-
wrote on 31 Jan 2014, 14:48 last edited by
QtSingleApplication is useful here if you want to start App2 if and only if it isn't running already... App1 can just spawn the process and be sure either way that the App2 is running. I've done this in the past quite successfully. I would advocate the IPC solution if you want the two apps to communicate however.
-
wrote on 1 Feb 2014, 14:46 last edited by
Thanks all,
I already know (and use) QtSingleApplication but, as you wrote, it only "deny" the same application execute more then one at the same time.Now I'm investigating on QSystemSemaphore.
Thanks again! -
wrote on 29 Aug 2014, 12:39 last edited by
Where is <QtSingleApplication>? I've got qt5 installed on my debian linux wheezy system and I get a "file not found" message when I say:
#include <QtSingleApplication>
-
wrote on 29 Aug 2014, 12:43 last edited by
QtSingleApplication has never been part of Qt proper, AFAIK. It always was an add on solution. That's why it is called QtSingleApplication, not QSingleApplication. The code can certainly be found floating around on the interwebs.
-
On "gitorious":https://qt.gitorious.org/qt-solutions :)