Pergunta

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?

Foi útil?

Solução

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).
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top