Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] QFile and qrc files = bad file descriptor



  • Hi everyone,

    I have an issue with QFile when opening a file found in my qrc file.
    What i'd like to do is to have a file descriptor on a file located in a qrc file.

    I successfully open in ReadOnly mode my file but when i ask for the handle I always get -1, is there anyway to get the file descriptor ? or it is simply impossible ?

    Thanks :)



  • @
    QFile file("foo.bar");
    file.open(QIODevice::ReadOnly);
    int fileHandle = file.handle();

    FILE* f = fdopen(fileHandle, "r");
    @

    Are you sure that code above is not working for your setup?


  • Lifetime Qt Champion

    Hi,

    @_tucnak_, It's not the same setup

    A file retrieved from Qt's resources is not the same a file from your own filesystem.

    However, there's a workaround for that, you can use QTemporaryFile. Open a temporary file, write the content of your resource in it and then use it for whatever you need.

    Hope it helps


Log in to reply