Important: Please read the Qt Code of Conduct -

get original file name of resource in qrc file

  • Hi all


    How can I get the original file name from the qrc resource file?

    More Info:

    Using fileName() and absoluteFilePath() methods, I implemented the following example:

    qrc entry:
    :/my/file           (somefile.txt)

    Here, I expect to see (atleast):




    Implemented Code:

    QFile file(":/my/file");
    QResource r(file.fileName)
    qDebug() << r.fileName();
    qDebug() << r.absoluteFilePath();



    Do I misunderstand the doc page, or am I just doing it wrong

  • Moderators

    @CybeX said

    How can I get the original file name from the qrc resource file

    You can't. The resources don't store that information once they're compiled. This information is useless in deployed app. If I had a file, say D:/MyDirectory/foo.txt , what good would that be on someone else's computer? There might not even be D: drive there.
    All QFile methods operate on the resource file, not on the original file so all paths will point to the resource file.

    What would you need that path for?

  • @Chris-Kawa

    It would actually just make things easier.

    I would like to generalize this procedure to e.g.

    QFile::copy(":/my/file", r.OriginalFileName);

    Here Qresource::OriginalFileName() returns the original file name e.g. somefile.txt

    Now, I am required to (for each file):

    QString newLocation = QString(tempdir + tempdir.seperator() +  QString("myNewFileName.txt"));
    QFile::copy(":/my/file", newLocation);

    It just seems tedious and not very efficient.

    But thanks for clearing it up though,

    *grabs coffee