Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3684

QFile: random access routines does not work properly, pos() always returns 0.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • P2: Important
    • 4.7.0
    • 4.5.0
    • Core: I/O
    • None

    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;
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            biochimia João Abecasis
            xcm Martin Petersson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes