Results 1 to 9 of 9

Thread: Cannot read QProcess output for some applications

  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Cannot read QProcess output for some applications

    Hi,
    I am trying to read console output of a qt console app from a qt gui app.

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. proc= new QProcess(this);
    4. connect(proc,SIGNAL(readyReadStandardOutput()),this,SLOT(readProcessOutput()));
    5. proc->setProcessChannelMode(QProcess::MergedChannels);
    6. proc->start("C:\\Users\\yg\\Documents\\processtest\\debug\\deployFiles.bat");
    7. }
    8. void MainWindow::readProcessOutput()
    9. {
    10. ui->textEdit->append(proc->readAllStandardOutput());
    11. }
    To copy to clipboard, switch view to plain text mode 

    I can read the output for "deployFiles.bat" app. But when i change the file to :
    Qt Code:
    1. proc->start("C:\\Users\\yg\\Documents\\processtest\\debug\\DriverModbus.exe");
    To copy to clipboard, switch view to plain text mode 

    Nothing comes to standartoutput.
    DriverModbus is a qt console app that uses qDebug() s to print data on its console.

    https://dl.dropboxusercontent.com/u/...iverModbus.rar

    What maybe the problem?

    Thanks in advance...

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Cannot read QProcess output for some applications

    qDebug write to stderr not stdout.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Cannot read QProcess output for some applications

    Hi Jefftee,

    I think "proc->setProcessChannelMode(QProcess::MergedChannels) " directs all output to stdout. So that shouldnt be a problem. And i already tried replacing "readyReadStandardOutput to readyReadStandardOutput" and "readAllStandardOutput toreadAllStandardError". Result not changing..

    And a few additional information ; i am sure the process is running. When i check its state i see it "running". And When i exit the application i see

    Qt Code:
    1. QProcess: Destroyed while process ("C:\Users\yg\Documents\processtest\debug\DriverModbus.exe") is still running
    To copy to clipboard, switch view to plain text mode 

    output on the console
    Last edited by yagabey; 5th July 2015 at 08:08.

  4. #4
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Cannot read QProcess output for some applications

    Ok, i discovered one more thing. I can read output when i use:

    Qt Code:
    1. QTextStream stream(stderr);
    2. stream << out;
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. QTextStream stream(stdout);
    2. stream << out;
    To copy to clipboard, switch view to plain text mode 

    But cannot read output from:

    Qt Code:
    1. qDebug() << out ;
    To copy to clipboard, switch view to plain text mode 

    Strange? No idea?

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Cannot read QProcess output for some applications

    Does the application output appears on a terminal when your run it normally?

    Cheers,
    _

  6. #6
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Cannot read QProcess output for some applications

    Yes, it does..

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Cannot read QProcess output for some applications

    One thing I could imagine is that the logging framework detects if there is a controlling terminal and output to it if there is.
    And if there is not it logs to some system logging factility

    Cheers,
    _

  8. #8
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Cannot read QProcess output for some applications

    Not a solution ;but for now i think i need to use "stdout" ...

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Cannot read QProcess output for some applications

    Yes, using the correct streams explicitly is a better solution anyway.
    More control of which stream something is written to and more control on how the data is formatted, etc.

    Cheers,
    _

  10. The following user says thank you to anda_skoa for this useful post:

    yagabey (6th July 2015)

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 of QProcess in runtime
    By silur in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2012, 19:16
  3. Read most recent output from QProcess's stdout
    By Lawand in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2010, 22:29
  4. Replies: 6
    Last Post: 26th January 2010, 08:56
  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.