Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved QFile open(QIODevice::WriteOnly) always giving false

    General and Desktop
    5
    8
    4945
    Loading More Posts
    • 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.
    • saitej
      saitej last edited by

      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 Reply Quote 0
      • m.sue
        m.sue last edited by m.sue

        Hi,
        the usual suspects:

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

        -Michael.

        1 Reply Last reply Reply Quote 3
        • mrjj
          mrjj Lifetime Qt Champion last edited by mrjj

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

          saitej 1 Reply Last reply Reply Quote 3
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 4
            • saitej
              saitej @mrjj last edited by

              @mrjj

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

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @saitej last edited by

                @saitej
                and does the "TAGGED" folder exists?

                saitej 1 Reply Last reply Reply Quote 2
                • saitej
                  saitej @mrjj last edited by

                  @mrjj

                  That was the mistake.
                  Thanks

                  1 Reply Last reply Reply Quote 1
                  • dheerendra
                    dheerendra Qt Champions 2022 last edited by

                    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 Reply Quote 4
                    • First post
                      Last post