I have an application in Qt. It is a window. This window has certain data that is displayed.
This window is launched from another application.
It is quite possible that the application be launched from different instances of the other application, with different data.
Let’s say I already have one instance of the application running, how do I ensure that if the application is called again, it should not launch another instance, and should instead refresh the data in the already existing window with the new set?
In a nutshell, One application having a single window, which displays refreshed data passed along with a different call.
EDIT : I checked it out. It should be sufficient to solve my problem. However, I cannot find the relevant files in my Qt installation. I learnt it was never a part of Qt solutions and has to be downloaded manually. If this is the case, will it affect any licensing issues?
EDIT 2 :
I have an Instance, let’s say, A, of the application open already. I try and launch an instance B. B sends a message to A.
Is it possible to check for certain conditions to be satisfied by A, using this message, and then the decision of whether to open B or not?
As such…
- A is already running
- B is now launched
- B sends a message to A
- A tries to confirm something using this message
- if message is true( let’s say), keep A running and open B as a new instance
- if not…close B, and let A use this new information to refresh data
Is this possible using QtSingleApplication, especially step 6 ? Or will a new instance close as soon as it detects an already running instance?
Also, how do I integrate QtSingleApplication within my application? Do I only need to include the header and cpp? I don’t wish to build a dll and work like that. Is there any other configuration required?
I’d be obliged if anyone could help.
What you are looking for is QtSingleApplication. When you call the application a second time, you can check
QtSingleApplication::isRunning()to see if another instance already exists. If it does, simply useQtSingleApplication::sendMessage()to alert the first instance that something has been called. Simply set up your application to be able to receive those messages (which you can be made aware of by connecting to theQtSingleApplication::messageReceived()signal), and react accordingly when you receive that signal.