Results 1 to 6 of 6

Thread: Problem uisng QTextStream

  1. #1
    Join Date
    Jul 2015
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Question Problem uisng QTextStream

    Hi , i want to use the QTextStream for stdin , stdout & stderr. Here is my code :

    Qt Code:
    1. #include <QString>
    2. #include <QFile>
    3. #include <QTextStream>
    4.  
    5. QTextStream Output(stdout);
    6. QTextStream Input(stdin);
    7. QTextStream Error(stderr);
    8.  
    9. int main() {
    10. QString Path;
    11. Output << "Enter your path : ";
    12. Input >> Path;
    13. if(!QFile::exist(Path)) {
    14. Error << "Error : path does not exist." << endl;
    15. exit(-1);
    16. }
    17. else {
    18. // Some work...
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    The Input >> & Error << will work , but the Output << won't print anything (Without any compile error) it will cause a runtime error , why ?

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem uisng QTextStream

    Quote Originally Posted by Arshia Aghaei View Post
    the Output << won't print anything (Without any compile error) it will cause a runtime error , why ?
    What kind of runtime error?

  3. #3
    Join Date
    Jul 2015
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Smile Re: Problem uisng QTextStream

    Quote Originally Posted by yeye_olive View Post
    What kind of runtime error?
    Error code -1073741510.

  4. #4
    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: Problem uisng QTextStream

    The signed 32 bit integer -1073741510 is 3221225786 when treated as an unsigned 32-bit integer, and 0xC000013A in hex.
    That code means, STATUS_CONTROL_C_EXIT {Application Exit by CTRL+C} The application terminated as a result of a CTRL+C.
    https://msdn.microsoft.com/en-us/library/cc704588.aspx

    The likely reason you get no output is because the QTextStream is buffered and you have done nothing to trigger an immediate flush.
    See QTextStream::flush() or the flush stream manipulator.

  5. #5
    Join Date
    Jul 2015
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Question Re: Problem uisng QTextStream

    Quote Originally Posted by ChrisW67 View Post
    The signed 32 bit integer -1073741510 is 3221225786 when treated as an unsigned 32-bit integer, and 0xC000013A in hex.
    That code means, STATUS_CONTROL_C_EXIT {Application Exit by CTRL+C} The application terminated as a result of a CTRL+C.
    https://msdn.microsoft.com/en-us/library/cc704588.aspx

    The likely reason you get no output is because the QTextStream is buffered and you have done nothing to trigger an immediate flush.
    See QTextStream::flush() or the flush stream manipulator.
    I don't want to use QTextStream::flush() or QTextStream::endl() , i want to get the input at the same line with the prompt ...
    What should i do then ?

  6. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Problem uisng QTextStream

    Using QTextStream::flush() won't cause the output position to move to a new line, but it will force the output to be displayed on stdout, which I believe is what you want to occur.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. QTextStream Problem
    By lahmitia in forum Newbie
    Replies: 3
    Last Post: 8th March 2011, 20:16
  2. QTextStream readLine() problem
    By walito in forum Newbie
    Replies: 11
    Last Post: 10th January 2011, 14:55
  3. QTextStream problem
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2007, 09:50
  4. how to access usb device uisng qt
    By amit_pansuria in forum General Programming
    Replies: 4
    Last Post: 11th April 2007, 12:11
  5. Problem with QTextStream
    By eter in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 15: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.