Results 1 to 11 of 11

Thread: How to display the output of a process in a TextEdit widget in real time?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2009
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Angry Re: How to display the output of a process in a TextEdit widget in real time?

    Still not working. The process is however running fine but TextEdit widget remains empty.
    My MainWindow class
    class MainWindow : public QMainWindow, private Ui::MainWindow
    {
    Q_OBJECT
    public:
    QProcess *myProcess;
    MainWindow(QMainWindow *parent = 0);

    private slots:
    void updateError();
    void updateText();
    };
    MainWindow.cpp
    Qt Code:
    1. void MainWindow::On_pushButton_startAnalysis_Click()
    2. {
    3. QObject *parent;
    4. myProcess= new QProcess(parent);
    5.  
    6. QString program = "./memviz ";
    7. QCoreApplication::processEvents();
    8. connect(myProcess, SIGNAL(readyReadStdError()), this, SLOT(updateError()));
    9. connect(myProcess, SIGNAL(readyReadStdOutput()), this, SLOT(updateText()));
    10. myProcess->start(program);
    11. }
    12.  
    13. void MainWindow::updateError()
    14. {
    15. QByteArray data = myProcess->readAllStandardError();
    16. textEdit_verboseOutput->append(QString(data));
    17. }
    18.  
    19. void MainWindow::updateText()
    20. {
    21. QByteArray data = myProcess->readAllStandardOutput();
    22. textEdit_verboseOutput->append(QString(data));
    23. }
    To copy to clipboard, switch view to plain text mode 

    Is some error still hiding there from my egle eyes?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to display the output of a process in a TextEdit widget in real time?

    what do you see in console when this code works?
    Qt Code:
    1. void MainWindow::On_pushButton_startAnalysis_Click()
    2. {
    3. QObject *parent;
    4. myProcess= new QProcess(parent);
    5.  
    6. QString program = "./memviz ";
    7. QCoreApplication::processEvents();
    8. qDebug() << connect(myProcess, SIGNAL(readyReadStdError()), this, SLOT(updateError()));
    9. qDebug() << connect(myProcess, SIGNAL(readyReadStdOutput()), this, SLOT(updateText()));
    10. myProcess->start(program);
    11. }
    12.  
    13. void MainWindow::updateError()
    14. {
    15. QByteArray data = myProcess->readAllStandardError();
    16. qDebug() << data;
    17. textEdit_verboseOutput->append(QString(data));
    18. }
    19.  
    20. void MainWindow::updateText()
    21. {
    22. QByteArray data = myProcess->readAllStandardOutput();
    23. qDebug() << data;
    24. textEdit_verboseOutput->append(QString(data));
    25. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jun 2009
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to display the output of a process in a TextEdit widget in real time?

    Oh its giving following error

    Qt Code:
    1. Object::connect: No such signal QProcess::readyReadStdError()
    2. Object::connect: (receiver name: 'MainWindow')
    3. Object::connect: No such signal QProcess::readyReadStdOutput()
    4. Object::connect: (receiver name: 'MainWindow')
    To copy to clipboard, switch view to plain text mode 

    But this error should also have appeared in the texEdit_verboseOutput.

    I said the program is working fine because i was actually generating an xml file with my 'memviz' application which is generated finely. Sorry din check the console earlier.

  4. #4
    Join Date
    Jun 2009
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to display the output of a process in a TextEdit widget in real time?

    Any idea about this error? Isn't it weird QProcess::readyReadStdError() is a signal provided by QProcess as i see it in Qt Assistant but still i am getting 'no such signal error'.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to display the output of a process in a TextEdit widget in real time?

    take a look at docs: there are only these signals QProcess::readyReadStandardError && QProcess::readyReadStandardOutput.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display the output of a process in a TextEdit widget in real time?

    set the
    void QProcess::setProcessChannelMode ( ProcessChannelMode mode )

    to QProcess::MergedChannels
    "Behind every great fortune lies a crime" - Balzac

  7. #7
    Join Date
    Jun 2009
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to display the output of a process in a TextEdit widget in real time?

    Ah...stupid me.

    Thanks. It's working now.

Similar Threads

  1. real time data display
    By hammer256 in forum Qt Programming
    Replies: 13
    Last Post: 25th March 2013, 16:47
  2. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  3. Display the camera frame in real time
    By alex_lue in forum Qt Programming
    Replies: 8
    Last Post: 27th July 2007, 10:31

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