Results 1 to 6 of 6

Thread: get the real path of a resource file

  1. #1
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default get the real path of a resource file

    Hi,

    is it possible to get the real path of a file that is added to the project with Qt's resource system?

    Namely I have "test.qrc" added to the project and a file in that that can be referred with ":/res/file.txt" but this is of course not the real path in the file system. Now the class QFile can handle with the problem (would be dissapointing otherwise... ) but I can't give this string for example to an std::ifstream or it is not enough information for otput logs etc.
    Szilvi

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: get the real path of a resource file

    I don't know whether this works, but it just might:
    QDir::absoluteFilePath ( const QString & fileName )

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: get the real path of a resource file

    Resources are compiled in the executable (or exits as external binary file containing ALL files specified in QRC). So I don't think that You can use this with standard file system mechanism.

  4. #4
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: get the real path of a resource file

    I tried QFileINfo's absoluteFilePath, but it returns also :/res/file.txt
    I have the bad feeling that unfortunatelly Lesiok is right.
    Szilvi

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: get the real path of a resource file

    Lesiok is absolutely right. There is no file on the (deployed) file system corresponding to ":/res/file.txt". If you need that the be the case then don't use the resources system, or copy the data from the resource system to a dynamically allocated temporary file for external consumption.

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: get the real path of a resource file


Similar Threads

  1. resource file
    By kavinsiva in forum Newbie
    Replies: 4
    Last Post: 18th August 2009, 22:28
  2. Replies: 3
    Last Post: 28th March 2009, 15:37
  3. Resource file in Qt4.4.0
    By jml in forum Qt Tools
    Replies: 0
    Last Post: 6th May 2008, 18:01
  4. the real file icons
    By freeskydiver in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2007, 10:46
  5. Resource file in a lib
    By Rodrigo in forum Qt Programming
    Replies: 4
    Last Post: 25th June 2007, 15:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.