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
QtWS25 Last Chance

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.
  • CybeXC Offline
    CybeXC Offline
    CybeX
    wrote on 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

    Chris KawaC 1 Reply Last reply
    0
    • CybeXC CybeX

      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

      Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on 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?

      CybeXC 1 Reply Last reply
      1
      • Chris KawaC Chris Kawa

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

        CybeXC Offline
        CybeXC Offline
        CybeX
        wrote on 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

        • Login

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