PDA

View Full Version : Program is running in command line mode and another instance is launched!?



hakermania
2nd July 2011, 13:57
Hello Developers :D

I have developed an application that takes command-line arguments.
The application has the ability to focus to the already running application if another instance is launched, by sending a message from the launched (new) application to the already open application.
So, the problem is that if the program is running with a command line argument (something that does not open the GUI, it runs in the console) and another instance is launched I don’t know what to do exactly…
The argument is running a function every 30min using a qtimer and does nothing else actually, so, should I have the app connected and ready to receive a signal and when it receive it from the another instance to call the w.show(); (where w is MainWindow w;) and stop the command line-mode and its functionality (also maybe display a message that the process X has stopped because another instance was launched) ?

I think that this is what I should do but not sure, and I don’t want to do something wrong and have to correct it afterwards… (also by doing my way of thinking, MainWindow w; should be global)

So, what would be your way to do it, or what do you expect to be the behaviour of a program if it had a command-line interface and GUI was called?

Thanks :)

ChrisW67
2nd July 2011, 22:46
The application has the ability to focus to the already running application if another instance is launched, by sending a message from the launched (new) application to the already open application.
Like http://doc.trolltech.com/solutions/4/qtsingleapplication/qtsingleapplication.html or http://www.qtcentre.org/wiki/index.php?title=SingleApplication.



I think that this is what I should do but not sure, and I don’t want to do something wrong and have to correct it afterwards… (also by doing my way of thinking, MainWindow w; should be global)

From your description I am not entirely sure I know what your problem actually is. How your application should behave if you start multiple instances is entirely up to you.