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

QFile::remove() fails when it should not.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P2: Important P2: Important
    • None
    • 4.6.1
    • Core: I/O
    • None
    • Windows

      If you setFileName() to a new file, prior error code is retained, which can cause operations on the new file name to fail when they should not.

      {
              // Create and close "foo"
              QFile file1("foo"); 
              file1.open(QIODevice::WriteOnly);
              file1.close();
              
              // Open "bar"
              file1.setFileName("bar"); 
              file1.open(QIODevice::WriteOnly);
      
              // Try to remove "bar", fails (as it should, because file1 has it open)
              QFile file2("bar");
              assert(!file2.remove()); // Causes error code to be set within file2
      
              // Try to remove "foo" (should succeed, because nobody has it open)
              file2.setFileName("foo"); 
              assert(file2.remove());   // Fails!!!
      }
      

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

            biochimia João Abecasis
            gladed Glade Diviney
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes