Results 1 to 7 of 7

Thread: QTextStream input and output executing in wrong order

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextStream input and output executing in wrong order

    Okay, so the buffering type explanation makes sense. I guess that different distributions might have different defaults for in/out/err, which are set in some other location (the kernel? libc?). Stderr on my system exhibited the same behavior as stdout (line buffering).

    I also found you can flush the stream with a manipulator, as in
    Qt Code:
    1. out << "Answer: " << flush;
    To copy to clipboard, switch view to plain text mode 
    which kind of takes care of my concern about writing too much code to do a simple thing.

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

    Default Re: QTextStream input and output executing in wrong order

    Your problem doesn't have anything to do with stdout (buffered) or stderr(not buffered).

    Your issue is with the QTextStream which is buffered. The flush in the code that i wrote is flushing the QTextStream buffer (not the stdout, your QTextStream has only the same name as std::cout, that is one reason i said you should use different names )
    Last edited by Zlatomir; 8th November 2010 at 09:04.

  3. #3
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextStream input and output executing in wrong order

    So, please correct me if I'm wrong, but there is no way then to make QTextStream unbuffered, and the only way to reliably output to the console is to write a newline or flush the buffer. It seems true that the text is being held up at QTextStream as you state, since both QTextStream and iostream wrap the same stdout file handle, while iostream "works" for me.

    That takes care of my problem, but I still wonder what would cause the same code to execute differently on different computers, and even change how it executes on the same system over time?

Similar Threads

  1. Core Application - Input/Output
    By Peppy in forum Qt Programming
    Replies: 4
    Last Post: 19th May 2010, 11:47
  2. Replies: 2
    Last Post: 2nd June 2008, 08:45
  3. output while executing should be redirected to text file
    By AnithaRagupathy in forum Qt Programming
    Replies: 3
    Last Post: 13th October 2007, 10:33
  4. QTextStream, input and readLine()
    By kramed in forum Newbie
    Replies: 6
    Last Post: 1st September 2007, 23:54
  5. Replies: 8
    Last Post: 27th March 2007, 10: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
  •  
Qt is a trademark of The Qt Company.