2
我想在Qt的項目中使用臨時文件QTemporaryFile是空
我試試這個代碼:
QTemporaryFile file;
file.open();
QTextStream stream(&file);
stream << content; // content is a QString
qDebug() << file.readAll();
但是控制檯顯示一個空字符串:
""
我如何寫QTemporaryFile
中的字符串?
這是行不通的:/我直接看文件(位於臨時文件夾),它是空的。 – Intelligide
@Intelligide,這可能是因爲'QTextStream'緩存了數據。我已經更新了答案,添加'stream.flush()'以確保數據立即進入文件。 – SingerOfTheFall
它適用於'flush'。謝謝 ;) – Intelligide