0

我检查了文件的位置是否正确,所以我不知道为什么我的程序不工作。我实际上已经看了几个小时,但我仍然无法找出问题所在。我真的很感激任何意见。

文本文件中的文本: Bob Janurary 1 2000 Math 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());
    }

}
4

1 回答 1

2

您正在检查文件是否正确打开

if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {

所以你的代码只有在文件没有正确打开的情况下才会执行。利用

if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
于 2014-01-26T16:49:53.303 回答