The code can be found below.

QFile *fd = new QFile();
fd->setFileName("TEST.txt");
fd->open(QIODevice::ReadWrite);
if(fd->exists() == true){
ui->textEdit->append("OK");}
ui->textEdit->append(QString::number(fd->write("Additional string")));

At textEdit canvas I receive the count of written chars, but it does not appear in file. After the second call of fd-> write(...) everything is fine, but why only at second time?

有帮助吗?

解决方案

The files are buffered, executing a write doesn't necessarily mean that the data will end up on the disk. To get all of the data written so far into the file, you need to do any of the following:

  1. flush() the file, or
  2. close() the file, or
  3. destroy the QFile instance (here by deleting fd).
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top