0
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();
}
读出1显示读入文件,但是读出2正在打印“”,因此未分配x。我已经尝试了很多变体,包括.append()和连接,但是仍然没有被赋值。包含所有必需的库。readLine()未正确保存
任何帮助是值得欢迎的,它可能是愚蠢的。在Qt中完成。
问候
该文件的第二行必须为空,因此在第二次调用readLine之后'x'包含一个空字符串。或者,第一行后面没有内容,所以'x'包含一个“null”QString。 –
因此,如果我初始化了x变量并使用了连接或追加,它是否可以解决这个问题? – Decsy12
你可以显示你打开的文件的例子,我运行相同的代码,我没有任何问题。我使用Linux和Qt 5.8 – eyllanesc