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::copy() locks my xlsx file when copying it from app resources to a local directory
Forum Updated to NodeBB v4.3 + New Features

QFile::copy() locks my xlsx file when copying it from app resources to a local directory

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 490 Views 1 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.
  • SamurayHS Offline
    SamurayHS Offline
    SamurayH
    wrote on last edited by SamurayH
    #1

    Hi,
    I've encouraged a weird behavior of QFile::copy when trying to copy an xlsx document from my app's resources into a local folder. The function succeeds but the new document becomes locked and can't be edited. Then I tried to do a "manual" copy, the problem disappeared!

    // This locks the copied document
    // QFile::copy(":/Resources/doc/document.xlsx", documentPath);
    
    // "manual" copy doesn't!
    QFile orginalDoc(":/Resources/doc/document.xlsx");
    orginalDoc.open(QIODevice::ReadOnly);
    
    QFile copyDoc(documentPath);
    copyDoc.open(QIODevice::WriteOnly);
    copyDoc.write(orginal.readAll());
    copyDoc.close();
    
    

    So I think there's an issue with QFile::copy, or it maybe a silly mistake, any ideas?

    "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you check the permissions of the file after the copy happens ?

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

      SamurayHS 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Did you check the permissions of the file after the copy happens ?

        SamurayHS Offline
        SamurayHS Offline
        SamurayH
        wrote on last edited by
        #3

        @SGaist I just checked, it has ReadOnly permission.. why?

        "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

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

          Because it's copied from a read only file system.

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

          SamurayHS 1 Reply Last reply
          2
          • SGaistS SGaist

            Because it's copied from a read only file system.

            SamurayHS Offline
            SamurayHS Offline
            SamurayH
            wrote on last edited by
            #5

            @SGaist You mean a resource file becomes read only when the app gets compiled?

            "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              The resource system is ready-only by design.

              You can use QFile::setPermissions to make it writable.

              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
              2
              • SamurayHS Offline
                SamurayHS Offline
                SamurayH
                wrote on last edited by
                #7

                Ooh true, silly mistake then.. Thanks @SGaist!

                "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

                1 Reply Last reply
                0

                • Login

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