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 can i prevent my app open multiple times with Qt?
Forum Updated to NodeBB v4.3 + New Features

How can i prevent my app open multiple times with Qt?

Scheduled Pinned Locked Moved General and Desktop
33 Posts 7 Posters 14.4k 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.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    I am using ubuntu and the way i check if another instance of my application is running is via a command called "pidof".
    I have heard about "QtSingleApplication":http://doc.qt.nokia.com/solutions/4/qtsingleapplication/qtsingleapplication.html but its kinda weird. Seeing "this topic":http://developer.qt.nokia.com/forums/viewthread/3387 ( the link is dead ) i can understand that QtSingleApplication was never a part of the Qt libs. Is there any full guide on how to use this function? From downloading-installing to implementing it at your app.

    P.S Should i stay with pidof or try the QtSingleApplication?
    Thanks for any answers :)

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Robbin
      wrote on last edited by
      #2

      If you have a target platform for which you develop, looking for pid could be the answer you're looking for, but it's not really all that great either (if your app crashes, the pid stays but the app doesn't work). There are examples about single instances of an application, but they are all "hacks". There is not Qt functionality about that (at least not with the GPL license).

      Common cross platform solution is to run a tcp server on localhost and try to connect to it on start up. If you app can connect, it means another instance of your app is running. There are ways to communicate between the two copies as well. I cannot help you with link pointing to the right code atm.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vsorokin
        wrote on last edited by
        #3

        Try QtSingleApplication - it's right way :)

        Link to repo: http://qt.gitorious.org/qt-solutions/qt-solutions

        --
        Vasiliy

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Leon
          wrote on last edited by
          #4

          [quote author="Vass" date="1315747553"]Try QtSingleApplication - it's right way :)

          Link to repo: http://qt.gitorious.org/qt-solutions/qt-solutions[/quote]

          Can u tell me. From all the files that are in qtsingleapplication.pro project which one should i see?

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vsorokin
            wrote on last edited by
            #5

            Open INSTALL.TXT file, and read how you can build QtSingleApplication as Shared Library. after you would do it, you can use QtSingleApplication Library in you program. See examples in examples directory.

            --
            Vasiliy

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Leon
              wrote on last edited by
              #6

              [quote author="Vass" date="1315761368"]Open INSTALL.TXT file, and read how you can build QtSingleApplication as Shared Library. after you would do it, you can use QtSingleApplication Library in you program. See examples in examples directory.[/quote]

              Can't install it.. It keeps saying the same message:
              !http://img690.imageshack.us/img690/4669/screenshotqtsingleappli.png(screen)!

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DenisKormalev
                wrote on last edited by
                #7

                Have you tried to run qmake and make commands? :)

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  Leon
                  wrote on last edited by
                  #8

                  yeah... qmake -> make -> ./configure
                  just the same message...

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DenisKormalev
                    wrote on last edited by
                    #9

                    Why do you run configure as last element? It should be executed first.

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lgeyer
                      wrote on last edited by
                      #10

                      It is ./configure -> qmake -> make.

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        Leon
                        wrote on last edited by
                        #11

                        O was reading not configured, when it is now configured..
                        So i quess now i completed the 3rd step of the install.txt. So after that what? The txt file is really messed up.

                        I still have an error when including the QtSingleApplication.

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          lgeyer
                          wrote on last edited by
                          #12

                          Are you using the QtSingleApplication files directly or are you using them as a library?
                          If so, did the library compile without any errors? If not, which?
                          What errors do you have when including QtSingleApplication?

                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            Leon
                            wrote on last edited by
                            #13

                            Ok so here is the complete outpout of ./configure -> qmake -> make ( http://paste.ubuntu.com/688207/ )
                            After doing that i am including QtSingleApplication at my app and it says QtSingleApplication is not declared.

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              lgeyer
                              wrote on last edited by
                              #14

                              Build looks fine. Have you set up include path correctly? Have you even included the neccessary header files?

                              1 Reply Last reply
                              0
                              • L Offline
                                L Offline
                                Leon
                                wrote on last edited by
                                #15

                                So you mean copying the qtsinglecoreapplication.h file at my project directory and then
                                @#include "qtsingleapplication.h"
                                @
                                ?

                                1 Reply Last reply
                                0
                                • L Offline
                                  L Offline
                                  lgeyer
                                  wrote on last edited by
                                  #16

                                  The usual way is to add the path to the include path in your project file.
                                  @
                                  INCLUDEPATH += <location_of_qtsingleapplication_headers>
                                  @
                                  In addition, the QtSingleApplication libraries have to be added too.
                                  @
                                  LIBS += -L<location_of_qtsingleapplication_libraries>
                                  LIBS += -l<name_of_qtsingleapplication_library>
                                  @
                                  And - of course - you will have to include the headers in your sources files too.
                                  @
                                  #include <QtSingleApplication>
                                  @

                                  1 Reply Last reply
                                  0
                                  • L Offline
                                    L Offline
                                    Leon
                                    wrote on last edited by
                                    #17

                                    So whats wrong with that:
                                    @INCLUDEPATH += <~/Downloads/qt-solutions-qt-solutions/qtsingleapplication/src>
                                    LIBS += -L<~/Downloads/qt-solutions-qt-solutions/qtsingleapplication/src>
                                    LIBS += -l<~/Downloads/qt-solutions-qt-solutions/qtsingleapplication/src/qtsinglecoreapplication.h>@
                                    ?

                                    1 Reply Last reply
                                    0
                                    • V Offline
                                      V Offline
                                      vsorokin
                                      wrote on last edited by
                                      #18

                                      Remove < and > simbols

                                      --
                                      Vasiliy

                                      1 Reply Last reply
                                      0
                                      • L Offline
                                        L Offline
                                        Leon
                                        wrote on last edited by
                                        #19

                                        Forgot.
                                        @INCLUDEPATH += ~/Downloads/qt-solutions-qt-solutions/qtsingleapplication/src
                                        LIBS += -L~/Downloads/qt-solutions-qt-solutions/qtsingleapplication/src
                                        LIBS += -l~/Downloads/qt-solutions-qt-solutions/qtsingleapplication/src/qtsinglecoreapplication.h@

                                        But still i cant
                                        @#include <QtSingleApplication>@
                                        at my cpp file.

                                        P.S Should it have a spece between -l and ~ symbol.?

                                        1 Reply Last reply
                                        0
                                        • V Offline
                                          V Offline
                                          vsorokin
                                          wrote on last edited by
                                          #20

                                          Try this

                                          @INCLUDEPATH += ~/Downloads/qt-solutions-qt-solutions/qtsingleapplication/src
                                          LIBS += -L~/Downloads/qt-solutions-qt-solutions/qtsingleapplication/src
                                          LIBS += -lqtsinglecoreapplication
                                          @

                                          --
                                          Vasiliy

                                          1 Reply Last reply
                                          0

                                          • Login

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