QFile::handle() returns -1 for files in resource



  • It seems QFile::handle() returns -1 for files in resource. It's not mentioned in the doc but is this expected behavior? I was hoping to get a valid file descriptor so that I can use other API that takes fd.

    I'm sure the file was opened successfully as open() returned true. I tested on Ubuntu Linux with Qt 4.7.0.



  • Documentation says :
    If the file is not open, or there is an error, handle() returns -1.
    So I will say please re check if the file is really open



  • Are you sure you are using the same file id?

    I mean you have a QFile variable and are using handle() on it after open()? Not just QFile::handle() as per topic.



  • Maybe some code snippets would be helpful to see what is the issue



  • For data in a Qt resource file (filename is ":/path/to/resource") there is no underlying file (the data itself is actually compiled into your executable), so there is no file descriptor either. You can use Qt resource only within Qt itself or extract the data to an array/QByteArray and hand that bunch of bytes over to your legacy code.



  • Thanks Volker, that makes sense.


Log in to reply
 

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