Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single instance application in Qt [duplicate]

Tags:

c++

qt

I would like to focus .exe file (more specifically console application) to one functioning program that the first time launched it works but when executed second time (while the first one exists) it could turn focus to the first launched programm. Is that possible at all in Qt?

like image 456
elgolondrino Avatar asked Aug 29 '13 05:08

elgolondrino


1 Answers

For single instance, read Run only one instance of a Qt application.

Disregarding portability, if you are running on Windows, another common approach is to create a named pipe (or a named mutex) when the application starts, and destroy it before exiting. If the named pipe already exists, another instance is already running. You could even write to the named pipe asking the other instance to bring its window to front, altough a console application might not benefit from this specifically.

Another way to focus the existing instance is to find the window of the already running instance, then call SetFocus on its HWND, or the corresponding function on your platform.

like image 82
jweyrich Avatar answered Nov 14 '22 11:11

jweyrich