Description
Open a file in exclusive share mode on Windows, so that no other applications can open it in read or write mode.
When you use seek in such a file, QFile::pos() will always returns 0.
Example Code:
#include <QFile> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <share.h> #include <io.h> int main(int argc, char *argv[]) { QFile f("Test.txt"); int nOpenMode = QIODevice::Truncate | QIODevice::ReadWrite | QIODevice::Unbuffered; int nOpenFlag = _O_CREAT | _O_TRUNC | _O_RDWR | _O_BINARY; int nFileDes = sopen("Test.txt", nOpenFlag, _SH_DENYRW, _S_IWRITE); if(nFileDes == -1) { return -1; } qDebug("Opened: %d", f.open(nFileDes, (QIODevice::OpenMode)nOpenMode)); qDebug("Is Sequential: %d", f.isSequential()); qDebug("Seek: %d", f.seek(5)); qDebug("Wrote: %ld", f.write("111", strlen("111"))); qDebug("Pos: %d", f.pos()); f.close(); return 0; }