Results 1 to 4 of 4

Thread: not able to read output from the terminal

  1. #1
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default not able to read output from the terminal

    this code was meant to compile a C file and read the errors encountered while compiling a file through gcc in ubuntu.
    my problem is that variable result is always empty, even in case of error containing file, result should have "errors" (these are same errors which are displayed in terminal if file is compiled )

    Qt Code:
    1. QProcess myProcess;
    2. QString program = "gcc";
    3. QStringList arguments;
    4. arguments << fileName;
    5. myProcess.start(program, arguments);
    6. myProcess.waitForFinished();
    7. QByteArray result = myProcess.readAllStandardOutput ();
    8. const QString a (result);
    9. if(!a.isEmpty())
    10. {
    11. QFont font1;
    12. font1.setFamily("Courier");
    13. font1.setFixedPitch(true);
    14. font1.setPointSize(10);
    15. font1.setBold(true);
    16.  
    17. QTextEdit *errorWindow;
    18. errorWindow = new QTextEdit;
    19. errorWindow->setFont(font1);
    20. errorWindow->setText(a);
    21. errorWindow->show();
    22. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: not able to read output from the terminal

    I think you show use signal slot mechanism to read standard output of process.
    like
    connect(&myProcess,SIGNAL(readyReadStandardOutput( )),this,SLOT(readStandardData());
    //readStandardData() is slot from where you can read data of your process.

    I hope this will help you..

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

    jack101 (26th March 2012)

  4. #3
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: not able to read output from the terminal

    Quote Originally Posted by MrShahi View Post
    I think you show use signal slot mechanism to read standard output of process.
    like
    connect(&myProcess,SIGNAL(readyReadStandardOutput( )),this,SLOT(readStandardData());
    //readStandardData() is slot from where you can read data of your process.

    I hope this will help you..
    no readStandardOutput() is a standard function of QProcess, i didn't used any signal slot mechanism for this part.

  5. #4
    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: not able to read output from the terminal

    Are you sure errors go to STDOUT and not STDERR?
    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.


Similar Threads

  1. why can't QProcess read all output?
    By Raul in forum Qt Programming
    Replies: 32
    Last Post: 15th June 2013, 12:17
  2. read output data
    By KillGabio in forum General Programming
    Replies: 4
    Last Post: 6th February 2012, 16:31
  3. Replies: 3
    Last Post: 27th August 2011, 21:44
  4. Read most recent output from QProcess's stdout
    By Lawand in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2010, 22:29
  5. Help on QProcess - Output Read
    By augusbas in forum Qt Programming
    Replies: 5
    Last Post: 24th September 2009, 11:54

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.