Do Qt Programs Have Permssion to Copy Files to the Users Directory?



  • I am trying to copy a file from a qrc resource location to a temporary location where microsoft word can open it. The copy() method in the code below returns false. Any ideas why? I think it might be because the program doesn't have permission to copy the file to the user directory.

    const QString GNULicenseCopyDirectory = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
    if (QFile::exists(GNULicenseCopyDirectory + "/COPYINGtemp.docx"))
        {
            QFile::remove(GNULicenseCopyDirectory + "/COPYINGtemp.docx");
        }
    bool results = QFile::copy(":/resources/Copying.docx",
    GNULicenseCopyDirectory + "/COPYINGtemp.docx");
    QDesktopServices::openUrl("file:///" + GNULicenseCopyDirectory + "/COPYINGtemp.docx");
    

  • Lifetime Qt Champion

    Hi,

    Are you sure the qrc path is correct ?

    You should also consider putting the path to the temp file in a variable. You are calling GNULicenseCopyDirectory + "/COPYINGtemp.docx" four times thus it means that if you modify the file name for whatever reasons, you'll have to do it also four times.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.