Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFile open(QIODevice::WriteOnly) always giving false
Forum Updated to NodeBB v4.3 + New Features

QFile open(QIODevice::WriteOnly) always giving false

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 5 Posters 5.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • saitejS Offline
    saitejS Offline
    saitej
    wrote on last edited by
    #1

    Hi

    I have code to write buffer to a new file. But it always return false. Can someone suggest the reason ?

    QFile fileWrite();
     fileWrite.open(QIODevice::WriteOnly);
    fileWrite.setFileName(imageDirectory + "/TAGGED/" + _imageList.at(i).fileName());
    qDebug() << fileWrite.fileName(); // gives the correct file name
    
    if (fileWrite.open(QIODevice::WriteOnly )){
    //doesnot enter this loop
                        fileWrite.write(imageBuffer);
                        fileWrite.close();
                    }
                    else {
    
                         qDebug() << fileWrite.openMode(); //gives NOT OPEN
                        qDebug() << "Geotagging failed. Couldn't write to an image";
                        return;
                    }
    
    1 Reply Last reply
    0
    • m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by m.sue
      #2

      Hi,
      the usual suspects:

      • the directory is write protected
      • the directory does not exist
      • the file name is illegal

      -Michael.

      1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi
        Did you check why it fails with
        http://doc.qt.io/qt-5/qfiledevice.html#error
        ?

        saitejS 1 Reply Last reply
        3
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          To add to my fellows, you start by opening a file without any name and then you try to open it again. That looks suspicious.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4
          • mrjjM mrjj

            Hi
            Did you check why it fails with
            http://doc.qt.io/qt-5/qfiledevice.html#error
            ?

            saitejS Offline
            saitejS Offline
            saitej
            wrote on last edited by
            #5

            @mrjj

            I am getting "The file could not be opened" error with error code 5 (QFileDevice::OpenError).

            mrjjM 1 Reply Last reply
            0
            • saitejS saitej

              @mrjj

              I am getting "The file could not be opened" error with error code 5 (QFileDevice::OpenError).

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @saitej
              and does the "TAGGED" folder exists?

              saitejS 1 Reply Last reply
              2
              • mrjjM mrjj

                @saitej
                and does the "TAGGED" folder exists?

                saitejS Offline
                saitejS Offline
                saitej
                wrote on last edited by
                #7

                @mrjj

                That was the mistake.
                Thanks

                1 Reply Last reply
                1
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #8

                  Error code 5 generally means you don't permission to open the file . Please check permissions

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  4

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved