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. Process launching, and killing
Forum Updated to NodeBB v4.3 + New Features

Process launching, and killing

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 6.3k 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.
  • K Offline
    K Offline
    kashifiqb
    wrote on last edited by
    #1

    Hello, I have to do the following but can't get any good way to start with. The application is to be developed for Mac and has to:

    1. Check if an application, say named "A", is running or not
    2. If it is running, the application has to terminate it
    3. If it is not running, I have to launch it

    I have done this in Windows very easily using windows api, but in Mac using Qt, i don't have any help..

    I couldn't get any help online and after all searching, I am posting this here.

    Kashif

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      You must use MAC specific APIs, Qt does not give that to you.
      You can start processes with QProcess, but monitoring already running processes and killing them, has to be done in a platform dependent way.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kashifiqb
        wrote on last edited by
        #3

        Thanks Gerolf for your reply...

        Actually I am using Qt Creator to do all my work, and don't know how to proceed towards what you are mentioning.. Can you guide me to achieve my objective?

        Kashif

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          QtCreator is just an IDE.
          You have to use the MAC APIs for that.
          But I am not a MAC user/developer, sorry.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • frankcyblogic.deF Offline
            frankcyblogic.deF Offline
            frankcyblogic.de
            wrote on last edited by
            #5

            Hi Kashif,

            you are looking for information out of the kernel. On Linux you find this in /proc. On Mac I'm not 100% sure, but the corresponding interface is called "sysctl". Check out the "manpagez":http://www.manpagez.com/man/3/sysctl/. If you are lucky you find example code in "Amit Singh's book":http://osxbook.com/

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              If you know the path of the application, just call QDesktopServices::openUrl on it:

              @
              QString appPath = "/Applications/Qt Creator.app";
              QDesktopServices::openUrl(QUrl::fromLocalFile(appPath));
              @

              It opens the application if it's not running. If it's already running, it brings it to the foreground.

              If you want to have the application stay in the background, you can use this snippet:

              @
              QStringList args;
              args << "-g"; // let the app stay in the background
              args << "/Applications/Qt Creator.app";
              int ok = QProcess::execute(cmd, args);
              qDebug() << "ok=" << ok;
              @

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • frankcyblogic.deF Offline
                frankcyblogic.deF Offline
                frankcyblogic.de
                wrote on last edited by
                #7

                Thanks, Volker, nice tip! I wasn't aware that openUrl() could do that;)

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  Oh, I missed one requirement to close a process.

                  Have a look at this "article on stackoverflow":http://stackoverflow.com/questions/2518160/programmatically-check-if-a-process-is-running-on-mac and try a google search on "mac check if application is running".

                  @unclewerner: A nice side effect of the "open" command on the mac, it can handle almost everything. I'm missing it badly on my linux boxes....

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  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