문제

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