Results 1 to 2 of 2

Thread: Why doesn't QTextStream wait for input?

  1. #1
    Join Date
    Oct 2011
    Location
    Turkey
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Why doesn't QTextStream wait for input?

    In this little program why doesn't in wait for input?
    Qt Code:
    1. #include <QtCore>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QTextStream in(stdin, QIODevice::ReadOnly);
    6. QTextStream out(stdout, QIODevice::WriteOnly);
    7.  
    8. QString str;
    9. out << "Enter something: ";
    10. in << str;
    11. out << "hello " << str << "\n";
    12.  
    13. return 0;
    14. }
    To copy to clipboard, switch view to plain text mode 
    When i execute this i get
    Qt Code:
    1. Enter something: hello
    2. Press <RETURN> to close this window...
    To copy to clipboard, switch view to plain text mode 
    So what is going on that i don't understand?

  2. #2
    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 doesn't QTextStream wait for input?

    You are using operator<<() when you should be using operator>>() at line 10

Similar Threads

  1. Replies: 6
    Last Post: 13th July 2011, 19:10
  2. How to make modal widget wait for input after it is shown.
    By cuiqimeng in forum Qt Programming
    Replies: 4
    Last Post: 17th December 2010, 06:12
  3. QTextStream input and output executing in wrong order
    By jrmrjnck in forum Qt Programming
    Replies: 6
    Last Post: 8th November 2010, 16:33
  4. Replies: 4
    Last Post: 5th February 2009, 10:13
  5. QTextStream, input and readLine()
    By kramed in forum Newbie
    Replies: 6
    Last Post: 1st September 2007, 23:54

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.