23,121
社区成员
发帖
与我相关
我的任务
分享
bool QFSFileEnginePrivate::flushFh()
{
Q_Q(QFSFileEngine);
// Never try to flush again if the last flush failed. Otherwise you can
// get crashes on some systems (AIX).
if (lastFlushFailed)
return false;
int ret = fflush(fh);
lastFlushFailed = (ret != 0);
lastIOCommand = QFSFileEnginePrivate::IOFlushCommand;
if (ret != 0) {
q->setError(errno == ENOSPC ? QFile::ResourceError : QFile::WriteError,
qt_error_string(errno));
return false;
}
return true;
}
qt only invokes fflush, which is a STD c library call (I could be wrong, but I did see stdio.h included). On its man page:
Note that fflush() only flushes the user-space buffers provided by
the C library. To ensure that the data is physically stored on disk
the kernel buffers must be flushed too, for example, with sync(2) or
fsync(2).
From what I have seen, qt's implementation doesn't guarantee anything for data integrity in this context. You may want to follow the recommendation above to explicitly call fsync instead.
Just my two cents. I am no a QT expert.
BTW, here is the source code browser where I read the above codes...
https://qt.gitorious.org/qt/kde-qt/source/983e244eca6cca1e11402b3af5470a07c2b22fc2:src/corelib/io/qfsfileengine.cpp#L520