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. get original file name of resource in qrc file

get original file name of resource in qrc file

Scheduled Pinned Locked Moved Unsolved General and Desktop
resourceqt 5.7qfileqresource
3 Posts 2 Posters 2.1k Views
  • 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.
  • C Offline
    C Offline
    CybeX
    wrote on 24 Jan 2017, 16:19 last edited by
    #1

    Hi all

    Problem:

    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):

    somefile.txt
    

    or

    :/my/somefile.txt
    

    Implemented Code:

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

    Output:

    ":/my/file"
    ":/my/file"
    

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

    C 1 Reply Last reply 24 Jan 2017, 16:33
    0
    • C CybeX
      24 Jan 2017, 16:19

      Hi all

      Problem:

      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):

      somefile.txt
      

      or

      :/my/somefile.txt
      

      Implemented Code:

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

      Output:

      ":/my/file"
      ":/my/file"
      

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

      C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 24 Jan 2017, 16:33 last edited by
      #2

      @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?

      C 1 Reply Last reply 24 Jan 2017, 16:48
      1
      • C Chris Kawa
        24 Jan 2017, 16:33

        @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?

        C Offline
        C Offline
        CybeX
        wrote on 24 Jan 2017, 16:48 last edited by
        #3

        @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

        1 Reply Last reply
        0

        3/3

        24 Jan 2017, 16:48

        • Login

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