The second QProccess is not running.



  • 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?



  • 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.


  • Moderators

    @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.



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



  • @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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.