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