readLine()未正确保存

时间:2017-04-21 22:32:18

标签: c++ qt c++14

void LoadWindow::on_Load_Open_Button_clicked()
{        
    QString load_filepath = ui->Load_FilePath_TextBox->text();      //Get text from textBox
    load_filepath.replace("\\","/");     //Replaces all '\' with '/' for filepath reading

    QFile loadFile(load_filepath);
    if (loadFile.open(QIODevice::ReadOnly))     //Open the file in read-only mode and only reads if file was opened properly
    {
        QTextStream in(&loadFile);
        qDebug() << "line in = " << in.readLine();      //ReadOut 1
        QString x = in.readLine();      

        qDebug() << "x = " << x;        //ReadOut 2
        ExtractInfo(x);

    }else{
        //error
    }
    loadFile.close();

}

ReadOut 1显示读入文件,但ReadOut 2正在打印“”,因此未分配x。我尝试了很多变种,包括.append()和连接,但仍然没有被分配。包括所有必需的库。

欢迎任何帮助,这可能是愚蠢的事。在Qt。中完成。

此致

1 个答案:

答案 0 :(得分:0)

没有评论所需的声誉,但我很好奇如果你注释掉你命名为ReadOut 1的行会发生什么。我怀疑in.readLine()为两个不同的调用提供了两个不同的答案,因为在这些函数的实现中,它们通常会继续进行输入的下一个项目(在本例中是下一行)。