Solved Standalone app that can be run only once at a time
-
@Gerald-L thank you for sharing opinion
But the main question for me now is how to understand wich launched application manages wich project. If there are two running app and each one has its own project (C:/project_1.prj and C:/project_2.prj) where and how to store the name of the current project for each app? -
@Please_Help_me_D
There are many possible approached. Earlier you referenced https://forum.qt.io/topic/83317/qt5-prevent-multiple-instances-of-application/. From there, you could useQSharedMemory
among your instances as your way of recording which current instance is working on which project, and take it from there.... -
Hi,
Just in case, QtSingleApplication works seamlessly across plateforme taking in charge the backend stuff needed.
-
@JonB thank you
I just read about shared memoryHow do you think if I solve my problem in the following way:
- create shared memory where I keep QList of app's instances id. When app is launched it checks how many apps are already run: if it is empty then write shared memory value 1 else add 1 to the last QList value and this will be id for this instance.
- define global variable which stores id of the instance
- define global variable wich stores project name chosen in current instance
Is this approach going to work?
Does global var works only for current instance or they are visible inside all the instances? -
No, global variables are not shared between instances of an application.
-
@SGaist hi,
How do you think should I use QtSingleApplication or approach based on a shared memory and global vars? Gloabl is used with extern modifier
Does QtSingleApplication fits my needs? -
As already said: global variables are not shared between instances.
Well, you wrote that you want to run one application instance only. That's what QtSingleApplication is designed for.
-
@SGaist
It seems to me the question has now changed.@Please_Help_me_D said in Standalone app that can be run only once at a time:
But the main question for me now is how to understand wich launched application manages wich project. If there are two running app and each one has its own project (C:/project_1.prj and C:/project_2.prj) where and how to store the name of the current project for each app?
The OP now wants to run multiple instances of his application, and be able to read/write what "project" each is on. I was thinking each could store this information in
QSharedMemory
. I guess you could also useQtSingleApplication::sendMessage()
to exchange that information, though that class seems more aimed at ensuring only one instance is running? -
@SGaist I confused you I'm sorry
I think I found a solution but just in case that it will be useful for somebody (I'm in doubt but still..) I rewrite the problem and the solution:
The problem
MyApp should be available to run in few instances. Each instance should work with its own project (bunch of files). If the first instance works with project_1 then this project shouldn't be available for other instances.The solution
To keep information which instance works with wich project I introduce global varQString PRJ_NAME;
withextern
modifier
To store list of opened projects I createQList <QString>
in shared memory and store therePRJ_NAME
of each instanceI think this should work
-
@JonB yes, the problem changed and I'm ashamed of that.. I'm sorry for confusing
But I think to avoid using
QtSingleApplication
(I don't feel that I need to run local server to communicate between instances) and simply do the above method based on Shared Memory -
@Please_Help_me_D
Your post has crossed with mine. Yes, I thought that is what you want now. The principle you outline is what I had in mind.