View Full Version : Problem uisng QTextStream
Arshia Aghaei
1st July 2015, 08:19
Hi , i want to use the QTextStream for stdin , stdout & stderr. Here is my code :
#include <QString>
#include <QFile>
#include <QTextStream>
QTextStream Output(stdout);
QTextStream Input(stdin);
QTextStream Error(stderr);
int main() {
QString Path;
Output << "Enter your path : ";
Input >> Path;
if(!QFile::exist(Path)) {
Error << "Error : path does not exist." << endl;
exit(-1);
}
else {
// Some work...
}
}
The Input >> & Error << will work , but the Output << won't print anything (Without any compile error) it will cause a runtime error , why ?
yeye_olive
1st July 2015, 09:38
the Output << won't print anything (Without any compile error) it will cause a runtime error , why ?
What kind of runtime error?
Arshia Aghaei
5th July 2015, 05:00
What kind of runtime error?
Error code -1073741510.
ChrisW67
5th July 2015, 07:31
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.
Arshia Aghaei
8th July 2015, 21:55
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 ?
jefftee
9th July 2015, 02:03
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.