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. Check if application is running
QtWS25 Last Chance

Check if application is running

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

    Hi all,
    I have 2 Qt applications: App1 and App2.
    I want App1 to check if App2 is running and start it.

    What should be the best way to check a running Qt application?

    Thanks

    1 Reply Last reply
    0
    • jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on last edited by
      #2

      Qt has a range IPC solutions available check the following:

      • "Inter-Process Communication in Qt":http://qt-project.org/doc/qt-4.8/ipc.html
      • "QtSingleApplication":http://doc.qt.digia.com/solutions/4/qtsingleapplication/qtsingleapplication.html

      The first is a reference to all the standard ways of communicating between two programs (QLocalServer/Socket being the easiest and most portable IMHO). The second is a special subclass of the QApplication that only allows a single instance of the application to be running at one time and therefore makes it easy to get a handle to that instance.

      Hope this helps ;o)

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      1 Reply Last reply
      0
      • C Offline
        C Offline
        cincirin
        wrote on last edited by
        #3

        ... or better use "QSystemSemaphore":http://qt-project.org/doc/qt-5/qsystemsemaphore.html

        QSystemSemaphore can be accessed from multiple processes

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          QtSingleApplication won't be a solution, as you're looking for two separate applications. QtSingleApplication is aimed at preventing two instances of the same application running.

          The link to the IPC and the QSystemSemaphore are useful tips though :)

          1 Reply Last reply
          0
          • jazzycamelJ Offline
            jazzycamelJ Offline
            jazzycamel
            wrote on last edited by
            #5

            QtSingleApplication is useful here if you want to start App2 if and only if it isn't running already... App1 can just spawn the process and be sure either way that the App2 is running. I've done this in the past quite successfully. I would advocate the IPC solution if you want the two apps to communicate however.

            For the avoidance of doubt:

            1. All my code samples (C++ or Python) are tested before posting
            2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
            1 Reply Last reply
            0
            • L Offline
              L Offline
              luca
              wrote on last edited by
              #6

              Thanks all,
              I already know (and use) QtSingleApplication but, as you wrote, it only "deny" the same application execute more then one at the same time.

              Now I'm investigating on QSystemSemaphore.
              Thanks again!

              1 Reply Last reply
              0
              • B Offline
                B Offline
                BowCatShot
                wrote on last edited by
                #7

                Where is <QtSingleApplication>? I've got qt5 installed on my debian linux wheezy system and I get a "file not found" message when I say:

                #include <QtSingleApplication>

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  QtSingleApplication has never been part of Qt proper, AFAIK. It always was an add on solution. That's why it is called QtSingleApplication, not QSingleApplication. The code can certainly be found floating around on the interwebs.

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

                    On "gitorious":https://qt.gitorious.org/qt-solutions :)

                    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

                    • Login

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