Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33

Thread: why can't QProcess read all output?

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: why can't QProcess read all output?

    Quote Originally Posted by Zlatomir View Post
    @Wysota: I didn't said you are wrong, and you are right about line-buffer in *nix, but this isn't a behavior that you can assume it's true (especially if you want multi-platform)
    Can you point a platform that doesn't perform a flush on newline?
    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.


  2. #22
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: why can't QProcess read all output?

    Quote Originally Posted by Raul View Post
    I just use QProcess start the program.and read the process.I didn't know how to request su first.if you can tell me how to request su first.
    Check out PAM.

    Quote Originally Posted by wysota View Post
    Can you point a platform that doesn't perform a flush on newline?
    What would also be interesting is that if you open a file as binary, you don't (or at least, I would expect you didn't) get flushing on newline. Do you get fliushing on endl even though the file is binary? I know using endl on a binary file is a bit strange, but it would be interesting to find out. Unless of course endl on a binary file causes a run time error?

  3. #23
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: why can't QProcess read all output?

    The OS might flush the stream with new line or might not, we can't know for sure, it might look that in 1000 cases flushes the stream and in one case, when we assume it does... the OS make us a surprise... (i saw some people surprised by this issue)

    I was talking from the C/C++ programmer point of view, for us there is no guarantee that the OS will flush on new line (\n), but in case the programmer isn't "happy" with the OS flushes, he can do it when he want it.

  4. #24
    Join Date
    May 2010
    Posts
    42

    Default Re: why can't QProcess read all output?

    [QUOTE=fatjuicymole;146411]Check out PAM.


    what the "PAM" reffers to?

  5. #25
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: why can't QProcess read all output?


  6. #26
    Join Date
    May 2010
    Posts
    42

    Default Re: why can't QProcess read all output?

    Quote Originally Posted by fatjuicymole View Post
    Then it seems like you can't get the same behaviour from your Qt app without first requesting su?
    I think my problem occurs without first requesting su.and i have studied the PAM.but i can't solve my problem yet,the main reason is that i don't know how to request su first.
    Last edited by Raul; 6th June 2010 at 19:25.

  7. #27
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: why can't QProcess read all output?

    Well, you can always give root access to your program permanently, if you don't want to request it whilst running:

    chown root your_app
    chmod a+xs your_app

  8. #28
    Join Date
    May 2010
    Posts
    42

    Default Re: why can't QProcess read all output?

    Quote Originally Posted by fatjuicymole View Post
    Well, you can always give root access to your program permanently, if you don't want to request it whilst running:

    chown root your_app
    chmod a+xs your_app
    the result is the same as before.

  9. #29
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: why can't QProcess read all output?

    Quote Originally Posted by Raul View Post
    I have knew that the second line end with a \n.and it should be the second possibility,but,before I start the program,I set the process like this:
    Qt Code:
    1. inprocess.setReadChannelMode(QProcess::MergedChannels);
    To copy to clipboard, switch view to plain text mode 
    and in the connect, I write like this:
    Qt Code:
    1. connect(&inprocess,SIGNAL(readyReadStandardOutput()),this,SLOT(iupdateTextEdit()));
    2. connect(&inprocess,SIGNAL(readyReadStandardError()),this,SLOT(iupdateTextEdit()));
    To copy to clipboard, switch view to plain text mode 
    the following show the iupdateTextEdit() fuction
    Qt Code:
    1. void mainWindow::iupdateTextEdit()
    2. {
    3. QByteArray newData=inprocess.readAllStandardOutput();
    4. QString text=textEdit->toPlainText()+QString::fromLocal8Bit(newData);
    5. textEdit->setPlainText(text);
    6. }
    To copy to clipboard, switch view to plain text mode 
    even so,it can't show the second line in the textEdit.
    We cannot see where, but you are allocating "inprocess" on the stack from the look of this. Are you sure that inprocess is not going out-of-scope at some inconvenient point in time? This might explain the "sometime works" behaviour.

  10. #30
    Join Date
    May 2010
    Posts
    42

    Default Re: why can't QProcess read all output?

    Quote Originally Posted by ChrisW67 View Post
    We cannot see where, but you are allocating "inprocess" on the stack from the look of this. Are you sure that inprocess is not going out-of-scope at some inconvenient point in time? This might explain the "sometime works" behaviour.
    I'm not sure.but in Qt,it almost declare a QProcess object .and hardly ever use "new" .what's more,the output only has two lines if it output all results. so i think it isn't like what you say.

  11. #31
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: why can't QProcess read all output?

    The amount of output you are expecting is irrelevant if the QProcess instance is being destroyed before you want it to be. It's also irrelevant how someone else chooses to create QProcess because it is your code with the problem, not theirs. The first example in the QProcess docs uses the heap for a long-running process, and the second uses a local (stack) variable to run a short-lived process entirely entirely within the same scope.

  12. #32
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: why can't QProcess read all output?

    Quote Originally Posted by fatjuicymole View Post
    What would also be interesting is that if you open a file as binary, you don't (or at least, I would expect you didn't) get flushing on newline. Do you get fliushing on endl even though the file is binary? I know using endl on a binary file is a bit strange, but it would be interesting to find out. Unless of course endl on a binary file causes a run time error?
    I would expect a binary stream to be buffered as well. Remember TCP is a binary stream and it is flushed on newline (there are no "modes" for creating a socket).
    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.


  13. #33

    Default Re: why can't QProcess read all output?

    If anyone is still interested, here is a possible workaround for the buffer problem:
    https://sites.google.com/site/marcst...output-channel

Similar Threads

  1. Can't get QProcess output
    By croscato in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2010, 15:56
  2. Problem with QProcess and output
    By mmm286 in forum Qt Programming
    Replies: 0
    Last Post: 3rd November 2009, 16:42
  3. Help on QProcess - Output Read
    By augusbas in forum Qt Programming
    Replies: 5
    Last Post: 24th September 2009, 11:54
  4. QProcess and capturing output
    By Aragorn in forum Qt Programming
    Replies: 7
    Last Post: 3rd May 2007, 16:57
  5. QProcess output in TreeView?!?
    By nupul in forum Qt Programming
    Replies: 1
    Last Post: 2nd May 2006, 08:05

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.