Results 1 to 4 of 4

Thread: help QProcess

  1. #1
    Join Date
    Jan 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy help QProcess

    Dear,
    I want to use QProcess to solve my problem.
    in my form, I have :
    1. lineedit to input command cell
    2. pushbutton to process command
    3. textedit for output process

    in my script i want to insert text :
    txtOutput->append("operation ending");
    after qprocess ending, but in my script, this text appear in top of output not in bottom textoutput.
    this script execute before process ending.
    how to make this script execute after qprocess ending?

    this is complete my scripts :

    Qt Code:
    1. #include "qtwiggle.h"
    2.  
    3. qtwiggle::qtwiggle(QWidget* parent)
    4. : QMainWindow(parent)
    5. {
    6. setupUi(this);
    7. setWindowTitle(tr("Tape Utilities"));
    8. }
    9.  
    10. void qtwiggle::on_btnRun_clicked()
    11. {
    12. QString perintah=txtInput->text();
    13. proc= new QProcess();
    14. proc->start("/bin/bash", QStringList() << "-c" << perintah);
    15. connect(proc, SIGNAL(readyReadStandardOutput()),this, SLOT(rightc()) );
    16. connect(proc, SIGNAL(readyReadStandardError()), this, SLOT(wrongc()) );
    17. txtOutput->append("operation ending");
    18. }
    19.  
    20. void qtwiggle::rightc()
    21. {
    22. QByteArray databaca = proc->readAllStandardOutput();
    23. txtOutput->append(databaca);
    24. }
    25.  
    26. void qtwiggle::wrongc()
    27. {
    28. QByteArray databaca = proc->readAllStandardError();
    29. txtOutput->append(databaca);
    30. }
    To copy to clipboard, switch view to plain text mode 
    thank you
    Last edited by jacek; 30th January 2008 at 14:54.

  2. #2
    Join Date
    Feb 2007
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: help QProcess

    My solution is clunky and there are probably better ways to do it. The upside is that it is simple and lets me colorize and format the strings I put out. I have a function which writes the text out for me:

    Qt Code:
    1. void appendStatusWindow(QTextEdit *wdt, QString s)
    2. {
    3. QString str = wdt->toHtml();
    4. if ( str.size() > 0 )
    5. {
    6. str.replace("<html>", "");
    7. str.replace("</html>", "");
    8. }
    9. str += s;
    10. str = "<html>\n" + str + "</html>\n";
    11. wdt->clear();
    12. wdt->append(str);
    13. wdt->ensureCursorVisible();
    14. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 31st January 2008 at 18:28. Reason: missing [code] tags

  3. #3
    Join Date
    Jan 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: help QProcess

    thank for your answer.
    but my complex problem is if I have two process. I want to run process 2 after process 1 ending. so I must know when process 1 ending.
    how to know that ?
    my problem above is a simple problem

    thanks you

  4. #4
    Join Date
    Jan 2008
    Location
    Russia, Chelyabinsk
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: help QProcess

    waitForFinished() and state() methods can help you...
    So you can code punk?

Similar Threads

  1. Questions about kill() and start() of QProcess
    By mp33919 in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2007, 13:00
  2. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  3. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 00:25
  4. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30
  5. QProcess in a QThread
    By chombium in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2006, 15:52

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
  •  
Qt is a trademark of The Qt Company.