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:
flush()
the file, orclose()
the file, orQFile
instance (here by deleting fd
).