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. QProcess::terminate() or QProcess::close()
Forum Updated to NodeBB v4.3 + New Features

QProcess::terminate() or QProcess::close()

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 207 Views 2 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote last edited by Perdrix
    #1

    My application starts its help viewer on macOS and Linux using QProcess::startDetached().

    When my application closes, should I:

    • Call QProcess::close() which will kill it? or
    • Call QProcess::terminate()

    The code currently uses close() :

    	if (helpProcess && helpProcess->state() == QProcess::Running)
    	{
    		helpProcess->close();
    	}
    

    Thanks, David

    Christian EhrlicherC 1 Reply Last reply
    0
    • PerdrixP Perdrix

      My application starts its help viewer on macOS and Linux using QProcess::startDetached().

      When my application closes, should I:

      • Call QProcess::close() which will kill it? or
      • Call QProcess::terminate()

      The code currently uses close() :

      	if (helpProcess && helpProcess->state() == QProcess::Running)
      	{
      		helpProcess->close();
      	}
      

      Thanks, David

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote last edited by
      #2

      @Perdrix said in QProcess::terminate() or QProcess::close():

      My application starts its help viewer on macOS and Linux using QProcess::startDetached().

      Then you can't close or terminate it at all...

      And the difference between close() and terminate() are properly documented - but reading seems to be very hard nowadays:

      close: Closes all communication with the process and kills it.
      terminate: Attempts to terminate the process. The process may not exit as a result of calling this function (it is given the chance to prompt the user for any unsaved files, etc).

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      PerdrixP 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Perdrix said in QProcess::terminate() or QProcess::close():

        My application starts its help viewer on macOS and Linux using QProcess::startDetached().

        Then you can't close or terminate it at all...

        And the difference between close() and terminate() are properly documented - but reading seems to be very hard nowadays:

        close: Closes all communication with the process and kills it.
        terminate: Attempts to terminate the process. The process may not exit as a result of calling this function (it is given the chance to prompt the user for any unsaved files, etc).

        PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote last edited by
        #3

        @Christian-Ehrlicher Yes, I can read I was asking for advice on which to use.

        But given the startDetached and either of those won't play together.

        I need to think again...

        D.

        JonBJ 1 Reply Last reply
        0
        • PerdrixP Perdrix

          @Christian-Ehrlicher Yes, I can read I was asking for advice on which to use.

          But given the startDetached and either of those won't play together.

          I need to think again...

          D.

          JonBJ Online
          JonBJ Online
          JonB
          wrote last edited by JonB
          #4

          @Perdrix
          Neither if using startDetached(). Of course your Help viewer will outlive your app, if that is not desirable you would need to "kill" it or use start(). Then you would have to use terminate(), or if you are in control of the Help viewer and want to be smart you could write it to detect close() and exit it then.

          1 Reply Last reply
          0
          • Kent-DorfmanK Offline
            Kent-DorfmanK Offline
            Kent-Dorfman
            wrote last edited by
            #5

            There is a concept in multi-processing that says you should not "have" to close or terminate a process/thread, but that you should signal it to end gracefully, and catch a status when it is done. ie, the responsibility for ending lies in the child itself, not in the parent, and that close/terminate are only for handlign exceptional error conditions. In some frameworks they haven't even implemented close/terminate.

            1 Reply Last reply
            2
            • PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote last edited by
              #6

              All well and good but that presumes that the process in question accepts input asking it nicely to close (probably on re-directed stdin). In this case the help display process doesn't support that.

              I've now changed to use start() instead of startDetached()

              Kent-DorfmanK 1 Reply Last reply
              0
              • PerdrixP Perdrix

                All well and good but that presumes that the process in question accepts input asking it nicely to close (probably on re-directed stdin). In this case the help display process doesn't support that.

                I've now changed to use start() instead of startDetached()

                Kent-DorfmanK Offline
                Kent-DorfmanK Offline
                Kent-Dorfman
                wrote last edited by
                #7

                @Perdrix said in QProcess::terminate() or QProcess::close():

                All well and good but that presumes that the process in question accepts input asking it nicely to close (probably on re-directed stdin). In this case the help display process doesn't support that.

                I've now changed to use start() instead of startDetached()

                Actually that's not entirely true. For a normal command line program it would terminate on its own, such as "ls, ps ax, df,...whatever", but in your case it's a little different. The POSIX way to tell a child to die gracefully is to send it a kill signal, which is different from using close/terminate. kill(pid, SIGTERM) kills a process, and can be trapped by the child to do cleanup. But in all fairness the QProcess::close() probably does that implicitly, whereas QProcess::terminate() is not "nice" about it.

                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