0
我檢查過,如果文件的位置是正確的,所以我不知道爲什麼我的程序不工作。我幾乎一直在看它幾個小時,但我仍然無法找出什麼是錯的。我真的很感激任何意見。Qt C++讀取while while循環不初始化
文本在文本文件中:鮑勃Janurary 1 2000數學7A 5 41 7 9 8 8 9
相關的代碼:
void MainWindow::on_pushButton_clicked()
{
QString name, month, subject, level;
int day, year, apages, total, one, two, three, four, five, six, seven, eight, nine, ten;
QFile file("C:/Users/brandan/Desktop/GUIPrograms/Kumon.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream stream(&file);
QString line;
do
{
qDebug() << "test";
line = stream.readLine();
qDebug() << line;
} while(!line.isNull());
}
}
「不工作」是什麼意思? – 0x499602D2
QDebug不輸出任何東西。 – user3183403
另外,爲什麼你的條件'if(!file.open(...))'?你正在檢查打開是否失敗,然後開始執行從文件讀取。相反,只要執行'if(file.open(...))'。 – 0x499602D2