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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With