Check if application is running
-
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
-
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)
-
... or better use "QSystemSemaphore":http://qt-project.org/doc/qt-5/qsystemsemaphore.html
QSystemSemaphore can be accessed from multiple processes
-
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 :)
-
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.
-
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! -
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>
-
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 :)