What happened to QtSingleApplication?
-
I'd like to know how to pass command line arguments to an already open program. So the user runs "backup.exe -job awef" and backup.exe recognizes there is an already open process and passes the argument to the already open process so users can command the program to do what they wish from the command line or a shortcut in windows.
I did a lot of research and found QtSingleApplication is deprecated...
Anybody know anything about the alternatives below? Are they reliable? Any other information to know?https://github.com/itay-grudev/SingleApplication
https://github.com/qtproject/qt-solutions/tree/master/qtsingleapplication -
You can do it using QLocalSocket and QLocalServer. when you start the application use a QLocalSocket and try to connect to an existing server if returns an error of type
QLocalSocket::ServerNotFoundError
then start the server.
If another instance of application will start it will try and succeed in the connection, you can then use the socket to transmit data between the two applications and, once done, make the second application quit -
Just clone the QtSolutions repository, you have everything there. The documentation will be same as the one you can find online but you can also build it when you build the module.
It's a module provided by The Qt Company.
-
@VRonin Not an ideal solution since it's on you to reinvent appropriate scoping.
For example, for a desktop Linux/BSD application, the proper solution would be to claim a static name on the session bus via QtDBus (Something like
com.you.YourApplication
), which has the added benefit of giving you a ready-made place to offer automation RPC to the rest of the desktop, such asraise()
. (Not to mention the pre-defined namespaces, like MPRIS.)At the very least, I'd incorporate the username or user ID into the server name when using
QLocalSocket
andQLocalServer
. -
@ssokolow said in What happened to QtSingleApplication?:
@VRonin Not an ideal solution since it's on you to reinvent appropriate scoping.
Perhaps, but rather simple and I'm pretty sure
QtSingleApplication
does it this way, too. -
Actually, I took at quick look at the source code and it looked like it was using a lockfile in the user profile, which means that it would be user-scoped rather than session-scoped.
(ie. Two separate sessions under the same account would interfere with each other.)
-
@ssokolow said in What happened to QtSingleApplication?:
Actually, I took at quick look at the source code and it looked like it was using a lockfile in the user profile, which means that it would be user-scoped rather than session-scoped.
I believe this is correct, yes.
-
Quote from the old days:
Trolltech provides platform- and industry-specific components and tools, as well as cutting-edge components too new to include directly in Qt
.That's what the Qt Solutions were originally.