Results 1 to 6 of 6

Thread: QProcess issue

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default QProcess issue

    Hey there,

    I keep having the same issue with QProcess:

    My run function:

    Qt Code:
    1. void qkReceptor::run()
    2. {
    3. // A timer to avoid high CPU charge
    4. QTimer timer;
    5.  
    6. connect(&timer, SIGNAL(timeout()), this, SLOT(onCheckStdin()), Qt::DirectConnection);
    7. connect(this, SIGNAL(newLine(QString)), this, SLOT(onNewLine(QString)), Qt::BlockingQueuedConnection);
    8.  
    9. timer.start(100);
    10.  
    11. QThread::exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    My stop function:

    Qt Code:
    1. void qkReceptor::stop()
    2. {
    3. if (this->isRunning())
    4. {
    5. this->quit();
    6. this->wait(); // This never return
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    My stop function doesn't seem to work on MacOSX, although it works on win32.

    Anyone ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess issue

    How do you call it? It has to be called from outside the thread. Are you sure you want the connection with the timer to be a direct connection? You do realize it will be a direct call "across" threads? The slot will be called on an object living in the main thread from the context of the worker thread.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QProcess issue

    Looks like we're right on it.

    When I comment :
    Qt Code:
    1. connect(&timer, SIGNAL(timeout()), this, SLOT(onCheckStdin()), Qt::DirectConnection);
    To copy to clipboard, switch view to plain text mode 

    The program exits properly.

    With DirectConnection I thought it would call the slot inside the thread.

    This thread is suppose to watch stdin.

  4. #4
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QProcess issue

    Tried this:

    Qt Code:
    1. void qkReceptor::run()
    2. {
    3. // A timer to avoid high CPU charge
    4. QTimer timer;
    5.  
    6. qkReceptorThread receptor;
    7.  
    8. connect(&timer, SIGNAL(timeout()), &receptor, SLOT(onCheckStdin()), Qt::DirectConnection);
    9. connect(&receptor, SIGNAL(newLine(QString)), this, SLOT(onNewLine(QString)), Qt::BlockingQueuedConnection);
    10.  
    11. timer.start(100);
    12.  
    13. QThread::exec();
    14. }
    15.  
    16. void qkReceptorThread::onCheckStdin()
    17. {
    18. QTextStream stream(stdin);
    19.  
    20. // return; // When returning here, the program exits properly.
    21.  
    22. // Do we have a new line to be read ?
    23. QString line = stream.readLine();
    24.  
    25. while (line.isNull() == false)
    26. {
    27. if (line.isEmpty() == false)
    28. {
    29. // Do something with our line
    30. emit newLine(line);
    31. }
    32.  
    33. line = stream.readLine();
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 

    Still doesn't work.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess issue

    I'd say you are blocking on readLine(). If there is nothing to read the function probably blocks until there is something to be read. You should use QSocketNotifier instead of such solution.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    bunjee (15th July 2009)

  7. #6
    Join Date
    Sep 2009
    Posts
    39
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Arrow Re: QProcess issue

    Hi to all,
    I'm using Embedded Linux Board. I tried to do Qprocess class implementation. by using all available examples I'm able to open Terminal program in Qt. Just i have a button on clicked.
    QString program="Terminal.exe";
    proc =new QProcess;
    proc->start(program);

    Now i'm gettin Terminal Window.I can execute some exe files by giving its exact PATH in program.Next process is to send Command "ls" to terminal by using Qt. By clicking on next (new) button.How can i send to terminal. now clicking on button, so im getting terminal Window, in the same window in need to send command "ls -l".

Similar Threads

  1. Replies: 3
    Last Post: 25th February 2009, 16:55
  2. Detect First QProcess finished in a group and kill other
    By Davidaino in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 12:53
  3. QProcess exitStatus()
    By user_mail07 in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 20:51
  4. QProcess and capturing output
    By Aragorn in forum Qt Programming
    Replies: 7
    Last Post: 3rd May 2007, 16:57
  5. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11

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.