Results 1 to 6 of 6

Thread: QTextStream does not read from stdin

  1. #1
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default QTextStream does not read from stdin

    Hello guys

    What's wrong with the code below that messagebox displays empty string??

    Qt Code:
    1. QTextStream stream(stdout);
    2.  
    3. std::cout<<"bla";
    4. qDebug()<<"ble";
    5.  
    6. QString line("initial");
    7.  
    8. line = stream.readLine();
    9.  
    10. QMessageBox::about(0,0,line);
    To copy to clipboard, switch view to plain text mode 
    Last edited by MasterBLB; 19th November 2012 at 10:13.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextStream does not read from stdin

    what is 'stdout' ? Please read my sig.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTextStream does not read from stdin


  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextStream does not read from stdin

    found it by myself,
    http://www.cplusplus.com/reference/c...cstdio/stdout/


    Added after 11 minutes:


    maybe QTextStream doesn't know buffer has changed...

    Qt Code:
    1. QTextStream stream(stdout);
    2.  
    3. stream<<"bla";
    4.  
    5. QString line = stream.readLine();
    6.  
    7. QMessageBox::about(0,0,line);
    To copy to clipboard, switch view to plain text mode 

    I expect that works better...
    Last edited by amleto; 20th November 2012 at 11:32.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTextStream does not read from stdin

    That surely works better,but won't help with my goal,which is a Qt GUI program intercepting all what has been sent to standard out and error (ext std::cout << "some input" then displaying that inside let's say QTextEdit.

  6. #6
    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: QTextStream does not read from stdin

    stdout stands for "Standard Output". The example you linked to uses stdin, which stands for "Standard Input".
    You can read from an input file handle and write to an output file handle, but only read/write from a file handle that has been opened for read and write.
    Neither of the to standard handles has been opened that way.

    You could start a wrapper program that uses QProcess to start the real program and read from the standard output of the child.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 3rd January 2012, 10:25
  2. QTextStream cannot read £ characters?
    By KjellKod in forum Qt Programming
    Replies: 10
    Last Post: 15th August 2011, 14:58
  3. Replies: 2
    Last Post: 9th June 2010, 16:08
  4. Replies: 5
    Last Post: 27th May 2009, 12:49
  5. Read/Write from QTextStream
    By tonde in forum Qt Programming
    Replies: 7
    Last Post: 31st July 2008, 16:51

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.