Single Instance Application in Qt

I would like to focus the .exe file (more specifically the console application) on one functioning program that launched it for the first time, but when it is executed a second time (while the first one exists), it can turn the focus into the first running program. Is this even possible in Qt?

+6
source share
1 answer

Read for one instance. Run only one instance of the Qt application .

Apart from portability, if you are running Windows, another general approach is to create a named pipe (or named mutex ) when the application starts and destroys it before exiting. If the named pipe already exists, another instance is already running. You can even write to a named pipe by asking another instance to bring its window to the foreground, although the console application may not use it specifically.

Another way to focus an 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.

+9
source

Source: https://habr.com/ru/post/952709/


All Articles