Results 1 to 3 of 3

Thread: Real time display of QProcess output in a textBrowser

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Real time display of QProcess output in a textBrowser

    Hello,
    I am a newbie in qt development and i want to transfer the output of QProcess to a textBrowser in real time. I started by executing a simple echo command,but the output of the program is not getting displayed.
    What am i doing wrong????

    Qt Code:
    1. p.start("echo", QStringList() << "hye");
    2. p.waitForStarted();
    3. QByteArray byteArray = p.readAllStandardOutput();
    4. QStringList strLines = QString(byteArray).split("\n");
    5. QString line= p.readAllStandardOutput();
    6. if(p.state()==QProcess::NotRunning)
    7. ui->textBrowser->append("not running");
    8. ui->textBrowser->append(line);
    9. p.waitForFinished();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Real time display of QProcess output in a textBrowser

    Try this code:
    Qt Code:
    1. QProcess *p = new QProcess( this );
    2.  
    3. if (p)
    4. {
    5. p->setEnvironment( QProcess::systemEnvironment() );
    6. p->setProcessChannelMode( QProcess::MergedChannels );
    7.  
    8. p->start( "cmd.exe", QStringList() << "echo" << "hye" );
    9. p->waitForStarted();
    10.  
    11. connect( p, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadOut()) );
    12. connect( p, SIGNAL(readyReadStandardError()), this, SLOT(ReadErr()) );
    13. }
    To copy to clipboard, switch view to plain text mode 
    And in slots ReadOut() and ReadErr():
    Qt Code:
    1. QProcess *p = dynamic_cast<QProcess *>( sender() );
    2.  
    3. if (p)
    4. ui->textBrowser->append( p->readAllStandardOutput() ); // p->readAllStandardError()
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Jonny174 for this useful post:

    Tanny007 (12th April 2012)

  4. #3
    Join Date
    Dec 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Smile Re: Real time display of QProcess output in a textBrowser

    Thanks for the solution...was looking for this.

Similar Threads

  1. real time data display
    By hammer256 in forum Qt Programming
    Replies: 13
    Last Post: 25th March 2013, 17:47
  2. Replies: 13
    Last Post: 11th January 2012, 15:19
  3. Replies: 1
    Last Post: 23rd September 2010, 21:16
  4. Replies: 10
    Last Post: 21st July 2009, 15:22
  5. Display the camera frame in real time
    By alex_lue in forum Qt Programming
    Replies: 8
    Last Post: 27th July 2007, 11: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.