PDA

View Full Version : Restore an application that is running while using QtSingleApplication



nobledeveloper
5th June 2007, 00:46
While a QtSingleApplication is running, if there is an attempt to start another instance of the application, is there a way to restore the application that is already running?

ber_44
5th June 2007, 06:01
Sorry for off-topic, but I badly need the QtSingleApplication code, can you send it over to
<mail address deleted>
Thank you in advance.

jacek
5th June 2007, 23:03
Sorry for off-topic, but I badly need the QtSingleApplication code, can you send it over to
If you need that code, you will have to buy a licence from the Trolls.

ber_44
6th June 2007, 10:45
If you need that code, you will have to buy a licence from the Trolls.

I don't mind having it unlicensed. Or do you know another solution that does not cost $$$?

Eldritch
6th June 2007, 15:38
I don't mind having it unlicensed. Or do you know another solution that does not cost $$$?

I'm sure you would not mind obtaining it improperly, but Trolltech would not take it kindly if their paying customers violated their license agreements and started giving away their product. That's um... what's the word? Oh, yeah... Illegal. ;)

I'm pretty sure if you search the forums, solutions to the 'single instance' that don't use the QtSingleApplication class from the Qt Solutions product have been discussed.

ber_44
6th June 2007, 18:44
I'm pretty sure if you search the forums, solutions to the 'single instance' that don't use the QtSingleApplication class from the Qt Solutions product have been discussed.

There is one thread at http://www.qtcentre.org/forum/f-qt-programming-2/t-instance-of-an-application-is-running-or-not-160.html
but it actually discusses a different problem than what its title suggests.
What solutions did you find?

Eldritch
7th June 2007, 03:34
Here (http://www.qtforum.org/thread.php?threadid=15933&hilight=single+instance)is one (it also mentions QtSingleApplication. ;-)

Often, the best solutions are platform-specific. You can use named pipes, a TCP or UPD connection, a simple file (these are all portable). In MSWin, the standard trick is a named mutex (not available on other platforms). I haven't looked at the code for QtSingleApplication, but it suggests the use of some form of pipe or socket just from its method list.

To the O.P.'s question. When the new instance checks for a previous one, the previous one will receive the text you send it. When it receives that message, it can activate its main window. It may not make the app jump to front (there's already a seperate thread about this), but it will restore its window if minimized, etc.

wysota
7th June 2007, 09:57
n MSWin, the standard trick is a named mutex (not available on other platforms).
On u*ix you can use system semaphores or message queues for that. Based on the fact that MacOS is also a u*ix, it should be available there as well. On modern Linuxes, it would be wise to just use dbus :)

ber_44
9th June 2007, 08:27
One thing that bothers me now is that when the user exits with Alt+F4 or through the Task Manager, then the mutex/textfile/etc. will never get deleted, so it will be impossible to restart the program.

elcuco
9th June 2007, 16:26
so... there is no gpl code available for doing this?

wysota
11th June 2007, 09:18
One thing that bothers me now is that when the user exits with Alt+F4 or through the Task Manager, then the mutex/textfile/etc. will never get deleted, so it will be impossible to restart the program.
You should be able to catch the signal using C function signal() and clean up the mutex before exiting the program.