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 Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on last edited by
    #1

    Hi,

    I almost have no experience of creating standalone executable file.

    There are two types of applications:

    1. one can run many times at the same time (each double click on executable file is going to execute new window with this app)
    2. one can run only once at a time. Another double click will produce an error that application is already running

    By default how the standalone application work? Does it launch new window with each double click or it can be run only once at a time?

    1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by Markkyboy
      #2

      Hi,

      I have created a couple of applications in QML that run on my Windows 7 64bit laptop. Certainly in my case, each time the .exe is double clicked, another instance is opened.

      I don't having any idea how to create a 'run once' application.

      A quick search revealed this; https://forum.qt.io/topic/83317/qt5-prevent-multiple-instances-of-application/ it might be of help, I don't really know, if it is, then your post is a duplicate :)

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      Please_Help_me_DP 1 Reply Last reply
      1
      • MarkkyboyM Markkyboy

        Hi,

        I have created a couple of applications in QML that run on my Windows 7 64bit laptop. Certainly in my case, each time the .exe is double clicked, another instance is opened.

        I don't having any idea how to create a 'run once' application.

        A quick search revealed this; https://forum.qt.io/topic/83317/qt5-prevent-multiple-instances-of-application/ it might be of help, I don't really know, if it is, then your post is a duplicate :)

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

        @Markkyboy Thank you for sharing your experience and for the link
        That is totally what I wanted
        I couldn't formulate my question nicer than I did so I didn't find this link by myself :(

        MarkkyboyM 1 Reply Last reply
        0
        • Please_Help_me_DP Please_Help_me_D

          @Markkyboy Thank you for sharing your experience and for the link
          That is totally what I wanted
          I couldn't formulate my question nicer than I did so I didn't find this link by myself :(

          MarkkyboyM Offline
          MarkkyboyM Offline
          Markkyboy
          wrote on last edited by
          #4

          @Please_Help_me_D - You're welcome :)

          Don't just sit there standing around, pick up a shovel and sweep up!

          I live by the sea, not in it.

          Please_Help_me_DP 1 Reply Last reply
          1
          • MarkkyboyM Markkyboy

            @Please_Help_me_D - You're welcome :)

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

            @Markkyboy there is dilemma that I cannot solve.
            I do want that my application to be available in few window (launched many times) but sinse my app allow user to create projects then I have to know project name of every launched MyApplication.
            For example user launches MyApp and opens C:/project_1.prj
            After that user launches MyApp and opens C:/project_2.prj

            In each instance of MyApp launched I need to know what project is chosen.
            I use SqLite and QSettings but I don't see straightforward way to store such information. Maybe global variables is useful in this sense?
            P.S. I didn't use global yet at all :)

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Gerald.L.
              wrote on last edited by Gerald.L.
              #6

              Imo, to be able to restrict the executable to be run only once, you should check the system's running progress table on your executable's startup to see if there is a progress running with your executable's name or some other information, if exists, exit, if not, run along.

              It's simple to make a two mainwindow appear, one created in main, the others created inside the existed mainwindow instance, the tricky part is to manage the shared data.

              With two executable running, it's two progress, and ipc (Inter-Process Communication) is very restricted compared to multi-thread solution.

              Please_Help_me_DP 1 Reply Last reply
              0
              • G Gerald.L.

                Imo, to be able to restrict the executable to be run only once, you should check the system's running progress table on your executable's startup to see if there is a progress running with your executable's name or some other information, if exists, exit, if not, run along.

                It's simple to make a two mainwindow appear, one created in main, the others created inside the existed mainwindow instance, the tricky part is to manage the shared data.

                With two executable running, it's two progress, and ipc (Inter-Process Communication) is very restricted compared to multi-thread solution.

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

                @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 2 Replies 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 Offline
                  JonBJ Offline
                  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 Offline
                              JonBJ Offline
                              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 Offline
                                    JonBJ Offline
                                    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