Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    The second QProccess is not running.

    General and Desktop
    qprocess
    4
    5
    1177
    Loading More Posts
    • 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.
    • F
      ForestPoem last edited by

      Hi.

      The second QProccess is not running.

      my source code.
      qProc = new QProcess;
      qProc->start("ifconfig"); <--running
      qProc->start("route"); <--not running.

      how to second command running?

      jsulm ValentinMichelet 2 Replies Last reply Reply Quote 0
      • JohanSolo
        JohanSolo last edited by

        Did you check if any of the process returned an error?

        What do you want to achieve with the ifconfig process? If you want to configure the connection, then you're a) missing arguments, 2) the configuration may not be complete when the "route" command is started.

        Beware that "Note: Processes are started asynchronously, which means the started() and error() signals may be delayed. Call waitForStarted() to make sure the process has started (or has failed to start) and those signals have been emitted." taken from the the doc.

        `They did not know it was impossible, so they did it.'
        -- Mark Twain

        1 Reply Last reply Reply Quote 0
        • jsulm
          jsulm Lifetime Qt Champion @ForestPoem last edited by

          @ForestPoem Do you really use the same QProcess instance to start the second process?!
          If so - do you wait until the first process finished?
          You can call qProc->state() to check the state of the process.

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

          1 Reply Last reply Reply Quote 0
          • JohanSolo
            JohanSolo last edited by

            @jsulm I missed the same instance was used twice! I need one more coffee to wake up ;-)

            `They did not know it was impossible, so they did it.'
            -- Mark Twain

            1 Reply Last reply Reply Quote 0
            • ValentinMichelet
              ValentinMichelet @ForestPoem last edited by ValentinMichelet

              @ForestPoem
              First, you have to understand that QProcess is running asynchronously. That means that in your two lines containing a start call, your second start is not waiting for the first process to stop.

              QProcess has some handful signals that tell you what it's doing:
              http://doc.qt.io/qt-5/qprocess.html#signals

              In particular, you have the finished signal that tells you when the process is done. From that you can connect a slot that will start your second process, here the "route" process.

              If you have a lot of processes to run in a row, I think you could add them to a QQueue member variable. Then, connect your QProcess finished signal to a custom slot that will start the next process until the QQueue is empty. You can also handle errors and decide what to do if anything wrong happens.

              If you want some code example, what you try to achieve is close to this:
              http://doc.qt.io/qt-5/qtnetwork-downloadmanager-example.html

              1 Reply Last reply Reply Quote 0
              • First post
                Last post