PDA

View Full Version : Create single instance of application Qt 5.4.1 Windows 7 Visual Studio 3013



TonyInSoMD
26th February 2018, 15:01
I'm trying to make it so that the program will run only one instance. Preferably if the user tries to open a new instance, it doesn't create a new instance and opens the instance that is already running. All the solutions I have have say use QtSingleApplication, but when I try to include the library, it doesn't exist.

d_stranz
26th February 2018, 16:31
QtSingleApplication was available in Qt4 (or Qt3) for commercial licensees only. It doesn't seem to have made it through the many ownership changes of Qt since then. I found a replacement on github which might work for you: https://github.com/itay-grudev/SingleApplication

TonyInSoMD
26th February 2018, 18:29
I appreciate the feedback. I hate to be a pain, but if possible, I need to find a way to do it within Qt without 3rd party plug-ins for security reasons. Qt has been approved, but it's about a 6 month to one year process to get something new approved. Since QtSingleApplication has been deprecated, anybody know of something I can do?

d_stranz
26th February 2018, 21:53
The mirror of the qt-project.org repository is here on git hub (https://github.com/qtproject). The original Qt Solutions repository, ported to Qt5 and released under LGPL licensing, contains QtSingleApplication and can be found within the qt-project repository.

It isn't part of the official Qt distribution (and never was - it was always a subscription-only add-on), so I don't know if it also counts as a "3rd party plug-in" under your definition.

AFAIK, the only way to do what you want is to dip into the Windows API. There is an example on MSDN (google "Limit Single Instance") which uses a cross-process shared mutex. QtSingleApplication does it using a file-locking mechanism (which itself uses a mutex created through the Windows API).