Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Standalone app that can be run only once at a time
Forum Updated to NodeBB v4.3 + New Features

Standalone app that can be run only once at a time

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 5 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Please_Help_me_DP Please_Help_me_D

    @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?

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #8

    @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 use QSharedMemory among your instances as your way of recording which current instance is working on which project, and take it from there....

    Please_Help_me_DP 1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #9

      Hi,

      Just in case, QtSingleApplication works seamlessly across plateforme taking in charge the backend stuff needed.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Please_Help_me_DP 1 Reply Last reply
      0
      • JonBJ JonB

        @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 use QSharedMemory among your instances as your way of recording which current instance is working on which project, and take it from there....

        Please_Help_me_DP Offline
        Please_Help_me_DP Offline
        Please_Help_me_D
        wrote on last edited by
        #10

        @JonB thank you
        I just read about shared memory

        How do you think if I solve my problem in the following way:

        1. 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.
        2. define global variable which stores id of the instance
        3. 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?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #11

          No, global variables are not shared between instances of an application.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Just in case, QtSingleApplication works seamlessly across plateforme taking in charge the backend stuff needed.

            Please_Help_me_DP Offline
            Please_Help_me_DP Offline
            Please_Help_me_D
            wrote on last edited by Please_Help_me_D
            #12

            @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?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #13

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              Please_Help_me_DP 1 Reply Last reply
              0
              • Please_Help_me_DP Please_Help_me_D

                @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?

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #14

                @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 use QtSingleApplication::sendMessage() to exchange that information, though that class seems more aimed at ensuring only one instance is running?

                Please_Help_me_DP 1 Reply Last reply
                0
                • SGaistS SGaist

                  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.

                  Please_Help_me_DP Offline
                  Please_Help_me_DP Offline
                  Please_Help_me_D
                  wrote on last edited by
                  #15

                  @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 var QString PRJ_NAME; with extern modifier
                  To store list of opened projects I create QList <QString> in shared memory and store there PRJ_NAME of each instance

                  I think this should work

                  JonBJ 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @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 use QtSingleApplication::sendMessage() to exchange that information, though that class seems more aimed at ensuring only one instance is running?

                    Please_Help_me_DP Offline
                    Please_Help_me_DP Offline
                    Please_Help_me_D
                    wrote on last edited by
                    #16

                    @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

                    1 Reply Last reply
                    0
                    • Please_Help_me_DP Please_Help_me_D

                      @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 var QString PRJ_NAME; with extern modifier
                      To store list of opened projects I create QList <QString> in shared memory and store there PRJ_NAME of each instance

                      I think this should work

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #17

                      @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.

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved