Results 1 to 4 of 4

Thread: QProcess and windows CreateProcess, read line by line

  1. #1
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QProcess and windows CreateProcess, read line by line

    Hi,
    I am rewriting my application from Borland to Qt. It calls an exe and pipes the output to the app. Originally I used CreateProcess, PeekNamedPipe etc. but these are native to windows and not multiplatform. I want to use QProcess and do not get very far. My simple code:
    Qt Code:
    1. calcProcess = new QProcess(this);
    2. connect(calcProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout()) );
    To copy to clipboard, switch view to plain text mode 
    and in readFromStdout():
    Qt Code:
    1. QString output;
    2. output = calcProcess->readAllStandardOutput();
    3. outputedit->appendPlainText(output); //outputedit is a PlainTextEdit
    To copy to clipboard, switch view to plain text mode 

    This seems to fill an output buffer (4096 bytes?) and the output is appended when the output buffer is full. I would then have to parse the output breaking it into strings with split or something.
    I have read that the signal is triggered each time the external exe produces something, and I want to read this output each time (per line). I have looked at many pieces of code in the forum but can't find how to do this. Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QProcess and windows CreateProcess, read line by line

    Since QProcess is a QIODevice, you can just use readLine();

  3. #3
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess and windows CreateProcess, read line by line

    Thanks, trying. It seems the app outputs everything on the error channel because there is no output on the stdout channel! In the code above I use in fact 'calcProcess->readAllStandardError();' sorry for miswriting that.
    In a dosbox the output looks like "Executing timestep n" where n is a number.
    Both readLine and readAllStandardError() give the output twice:
    ...
    Executing timestep 3
    Executing timestep 3
    Executing timestep 4
    Executing timestep 4
    ...
    etc.
    Also the readLine just fills up the buffersize that I give (so it acts like readAllStandardError) and does not seem to see a '\n' but the output breaks into lines like the ones shown (I tried writing to a file and to PlainTextEdit). Any ideas?

  4. #4
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess and windows CreateProcess, read line by line

    sorry, not a Qt problem but related to the programme I am calling

Similar Threads

  1. Problem using QProcess on Windows XP
    By shopov in forum Newbie
    Replies: 3
    Last Post: 29th April 2010, 12:28
  2. read stdout with QProcess under Windows
    By jlbrd in forum Qt Programming
    Replies: 4
    Last Post: 1st September 2006, 17:29
  3. need help for QProcess under windows
    By patcito in forum Qt Programming
    Replies: 4
    Last Post: 26th May 2006, 19:54
  4. QProcess +standard error + windows
    By antonio.r.tome in forum Qt Programming
    Replies: 0
    Last Post: 18th April 2006, 14:58
  5. Qprocess never end in MS windows
    By antonio.r.tome in forum Qt Programming
    Replies: 12
    Last Post: 23rd February 2006, 12:35

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.