Results 1 to 3 of 3

Thread: Sequential execution of QProcesses

  1. #1
    Join Date
    Mar 2017
    Posts
    12
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Sequential execution of QProcesses

    I have 5 QT processes in a slot, which invokes 5 shell scripts on linux system. I have arranged them in a sequential manner but when I had a look at logs, came to know that the processes are not running in a sequential manner. The order of execution gets change
    For eg
    Qt Code:
    1. void Window::slotProcess(){
    2.  
    3. statusWindow->setText("Running process");
    4.  
    5. /******************* STEP 1: START A NEW PROCESS 1 ***************/
    6. Process_1 = new QProcess(this);
    7. // Connet SIGNAL::STANDARD ERROR with SLOT::UPDATE ERROR, to capture std output
    8. qDebug() << connect(Process_1, SIGNAL(readyReadStandardError()), this, SLOT(UpdateError()));
    9. // Connect SIGNAL::STANDARD OUTPUT with SLOT::UPDATE OUTPUT to capture std error
    10. qDebug() << connect(Process_1, SIGNAL(readyReadStandardOutput()), this, SLOT(UpdateOutput()));
    11. Process_1->start("/home/root/scripts/script_1.sh");
    12.  
    13. /******************* STEP 2: START A NEW PROCESS 2 ***************/
    14. Process_2 = new QProcess(this);
    15. // Connet SIGNAL::STANDARD ERROR with SLOT::UPDATE ERROR, to capture std output
    16. qDebug() << connect(Process_2, SIGNAL(readyReadStandardError()), this, SLOT(UpdateError()));
    17. // Connect SIGNAL::STANDARD OUTPUT with SLOT::UPDATE OUTPUT to capture std error
    18. qDebug() << connect(Process_2, SIGNAL(readyReadStandardOutput()), this, SLOT(UpdateOutput()));
    19. Process_2->start("/home/root/scripts/script_2.sh");
    20.  
    21. .....
    To copy to clipboard, switch view to plain text mode 

    But when I see debug messages, it shows there is no sequence in execution. How can I control the sequence of execution of my processes?
    The wait for finish method will block the code, is there an alternative ?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,444
    Thanked 269 Times in 264 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sequential execution of QProcesses

    Use QProcess::waitForFinished before starting next process.
    Oops : You do not want to use a waitForFinished.

    Create one master script which will call subscripts.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,531
    Thanks
    13
    Thanked 1,576 Times in 1,505 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Sequential execution of QProcesses

    Lesiok's option is probably the least effort. Here are some other options:

    Create a slot for each step. In the slot for step 1 start the relevant process and connect() its finished() signal to the slot for step 2... and so on. You should check the exit state of step n at the top of step n+1 before starting the new step's process.

    Or, between steps:
    Qt Code:
    1. connect(process, SIGNAL(finished(...)), &loop, SLOT(quit()));
    2. loop.exec();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Instructions are NOT sequential in qt/qml?!?
    By JaySDC in forum Qt Quick
    Replies: 9
    Last Post: 24th October 2015, 17:41
  2. Sequential animations on each listitem
    By rama.kesi in forum Qt Quick
    Replies: 3
    Last Post: 12th October 2012, 03:36
  3. Sequential animations on each listitem
    By rama.kesi in forum Qt Quick
    Replies: 0
    Last Post: 8th October 2012, 05:24
  4. Multiple QProcesses running in parallel
    By doggrant in forum Qt Programming
    Replies: 4
    Last Post: 3rd November 2010, 16:41
  5. How should I thread these QProcesses?
    By last2kn0 in forum Qt Programming
    Replies: 8
    Last Post: 9th October 2007, 04:56

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.