Hi, I am a new new Qt student. haven't quite captured Qt's feature. First I say thank you all for your viewing this post.
Today I have written such codes:
#include <QtGui>
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Before the while loop." << '\n';
while (! in.atEnd())
{
std::cout << "a Line" << std::endl;
Line = in.readLine();
}
std::cout << "Finished the loop" << std::endl;
file.close();
return app.exec();
}
#include <QtGui>
#include <iostream>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QFile file("text.txt");
file.open(QIODevice::ReadOnly);
QTextStream in(&file);
std::cout << "Before the while loop." << '\n';
QString Line;
while (! in.atEnd())
{
std::cout << "a Line" << std::endl;
Line = in.readLine();
}
std::cout << "Finished the loop" << std::endl;
file.close();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
the text.txt has four lines.
So I am hopefully expecting the console output like:
Before the while loop.
a Line
a Line
a Line
a Line
Finished the loop
But after I went into the release folder and type the program name, the result was disappointing:
Before the while loop.
Finished the loop
Something is more strange, I use Code::Blocks. So if I compiled the program there and then hit its run button, the result was right, four "a Line" with the both head and tail statements.
And I haven't forgotten added in the .pro file such a line
CONFIG += console
So my question are:
What is wrong with my program? why make.exe -> in console type the program doesn't show the four "a line"? But Code::Blocks could build the program correctlly and run it reasonally?
Thank you all!!!
Bookmarks