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. how to create Singleinstance application
Forum Updated to NodeBB v4.3 + New Features

how to create Singleinstance application

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 3.7k Views
  • 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.
  • B Offline
    B Offline
    Bharth
    wrote on 11 Jan 2019, 10:58 last edited by
    #1

    hi,,,
    if im running exe file its opening application again if i click exe file it is opening new application ,,,
    i want only one application if it is already opened it should show Qmessaagebox

    please help me,,,,
    thanks in advance

    R J 2 Replies Last reply 11 Jan 2019, 11:02
    0
    • B Bharth
      11 Jan 2019, 10:58

      hi,,,
      if im running exe file its opening application again if i click exe file it is opening new application ,,,
      i want only one application if it is already opened it should show Qmessaagebox

      please help me,,,,
      thanks in advance

      R Offline
      R Offline
      Ratzz
      wrote on 11 Jan 2019, 11:02 last edited by Ratzz 1 Nov 2019, 11:12
      #2

      @Bharth
      You can make use of QtSingleApplication https://doc.qt.io/archives/qtextended4.4/qtopiadesktop/qtsingleapplication.html
      How to use them here.
      Good example by using QLockFile http://blog.aeguana.com/2015/10/15/how-to-run-a-single-app-instance-in-qt/

      --Alles ist gut.

      B 1 Reply Last reply 11 Jan 2019, 11:11
      4
      • B Bharth
        11 Jan 2019, 10:58

        hi,,,
        if im running exe file its opening application again if i click exe file it is opening new application ,,,
        i want only one application if it is already opened it should show Qmessaagebox

        please help me,,,,
        thanks in advance

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 11 Jan 2019, 11:03 last edited by
        #3

        @Bharth
        I do this via a QSharedMemory instance, I'm not sure if thats the best way to do it though.

        //insice main.cpp
        QSharedMemory _singular("myAppNameInstance");
            if(_singular.attach(QSharedMemory::ReadOnly)){
                //Instance Already running
                _singular.detach();
                //Your MessageBox-code should go here
                return -42;
            }else{
               //Program is not yet running.
                _singular.create(1);
            }
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        B 1 Reply Last reply 11 Jan 2019, 11:25
        2
        • R Ratzz
          11 Jan 2019, 11:02

          @Bharth
          You can make use of QtSingleApplication https://doc.qt.io/archives/qtextended4.4/qtopiadesktop/qtsingleapplication.html
          How to use them here.
          Good example by using QLockFile http://blog.aeguana.com/2015/10/15/how-to-run-a-single-app-instance-in-qt/

          B Offline
          B Offline
          Bharth
          wrote on 11 Jan 2019, 11:11 last edited by
          #4

          @Ratzz said in how to create Singleinstance application:

          @Bharth
          You can make use of QtSingleApplication https://doc.qt.io/archives/qtextended4.4/qtopiadesktop/qtsingleapplication.html
          How to use them here.

          i checked this one it is showing file not found
          #include<QtSingleApplication>

          R 1 Reply Last reply 11 Jan 2019, 11:17
          0
          • B Bharth
            11 Jan 2019, 11:11

            @Ratzz said in how to create Singleinstance application:

            @Bharth
            You can make use of QtSingleApplication https://doc.qt.io/archives/qtextended4.4/qtopiadesktop/qtsingleapplication.html
            How to use them here.

            i checked this one it is showing file not found
            #include<QtSingleApplication>

            R Offline
            R Offline
            Ratzz
            wrote on 11 Jan 2019, 11:17 last edited by Ratzz 1 Nov 2019, 11:20
            #5

            @Bharth said in how to create Singleinstance application:

            it is showing file not found

            Its not part of Qt. You need to download and add them to your project.
            You can download from here .

            --Alles ist gut.

            B 1 Reply Last reply 11 Jan 2019, 12:12
            1
            • J J.Hilk
              11 Jan 2019, 11:03

              @Bharth
              I do this via a QSharedMemory instance, I'm not sure if thats the best way to do it though.

              //insice main.cpp
              QSharedMemory _singular("myAppNameInstance");
                  if(_singular.attach(QSharedMemory::ReadOnly)){
                      //Instance Already running
                      _singular.detach();
                      //Your MessageBox-code should go here
                      return -42;
                  }else{
                     //Program is not yet running.
                      _singular.create(1);
                  }
              
              B Offline
              B Offline
              Bharth
              wrote on 11 Jan 2019, 11:25 last edited by
              #6

              @J.Hilk said in how to create Singleinstance application:

              myAppNameInstance

              QMessageBox::information(this,"Application is already running...","appname");

              this keyword showing error,,,,invalid use of this

              why you are retunring -42 what is the meaning...

              thanks for your reply

              J 1 Reply Last reply 11 Jan 2019, 11:32
              0
              • B Bharth
                11 Jan 2019, 11:25

                @J.Hilk said in how to create Singleinstance application:

                myAppNameInstance

                QMessageBox::information(this,"Application is already running...","appname");

                this keyword showing error,,,,invalid use of this

                why you are retunring -42 what is the meaning...

                thanks for your reply

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 11 Jan 2019, 11:32 last edited by J.Hilk 1 Nov 2019, 11:39
                #7

                @Bharth
                the main.cpp is not QObject based class, so you can't give QMessageBox this as parent.

                why you are retunring -42 what is the meanin

                The Answer to the Ultimate Question of Death, The Universe, and Everything ...

                The boring answer: an arbitrary return value I choose to identify the exit of the application.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                5
                • R Ratzz
                  11 Jan 2019, 11:17

                  @Bharth said in how to create Singleinstance application:

                  it is showing file not found

                  Its not part of Qt. You need to download and add them to your project.
                  You can download from here .

                  B Offline
                  B Offline
                  Bharth
                  wrote on 11 Jan 2019, 12:12 last edited by
                  #8

                  @Ratzz said in how to create Singleinstance application:

                  @Bharth said in how to create Singleinstance application:

                  it is showing file not found

                  Its not part of Qt. You need to download and add them to your project.
                  You can download from here .

                  i downloaded but i dont know which i should add to my project

                  R 1 Reply Last reply 11 Jan 2019, 12:18
                  0
                  • B Bharth
                    11 Jan 2019, 12:12

                    @Ratzz said in how to create Singleinstance application:

                    @Bharth said in how to create Singleinstance application:

                    it is showing file not found

                    Its not part of Qt. You need to download and add them to your project.
                    You can download from here .

                    i downloaded but i dont know which i should add to my project

                    R Offline
                    R Offline
                    Ratzz
                    wrote on 11 Jan 2019, 12:18 last edited by
                    #9

                    @Bharth said in how to create Singleinstance application:

                    i dont know which i should add to my project

                    For me this works
                    alt text

                    --Alles ist gut.

                    1 Reply Last reply
                    3
                    • B Offline
                      B Offline
                      Bharth
                      wrote on 12 Jan 2019, 05:39 last edited by
                      #10

                      thanks for your reply ,,,i will try

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        Bharth
                        wrote on 14 Jan 2019, 10:28 last edited by
                        #11

                        its working but not able to show qmessagebox,,,,
                        again if i click exe file it should open old one now its not opening

                        jsulmJ 1 Reply Last reply 14 Jan 2019, 12:34
                        0
                        • B Bharth
                          14 Jan 2019, 10:28

                          its working but not able to show qmessagebox,,,,
                          again if i click exe file it should open old one now its not opening

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 14 Jan 2019, 12:34 last edited by
                          #12

                          @Bharth said in how to create Singleinstance application:

                          again if i click exe file it should open old one now its not opening

                          Do you mean you want to show a message if you try to start a second instance?
                          Then simply do it inside this block:

                          if (instance.sendMessage("Wake up!"))
                          {
                              QMessageBox::information(nullptr, "Information", "Already running!", ...);
                              return 0;
                          }
                          

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          3
                          • B Offline
                            B Offline
                            Bharth
                            wrote on 14 Jan 2019, 13:25 last edited by
                            #13

                            @jsulm said in how to create Singleinstance application:

                            QMessageBox::information(nullptr, "Information", "Already running!", ...);

                            thank you so much its worked....

                            1 Reply Last reply
                            0

                            2/13

                            11 Jan 2019, 11:02

                            topic:navigator.unread, 11
                            • Login

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