[SOLVED] QFile open problem with path to resource file



  • Hi,

    I have this code:

    @QFile file(fileName);
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
    qDebug() << "Could not open file:" << file.errorString();
    file.close();
    return;
    }@

    If filename = "/absolute/path/to/appSettings.json" it opens the file.
    If filename = ":/config/appSettings.json" it throws an Unknown error.

    The thing is, I have the same code for reading the file, and it works with both versions of the path, so the qrc file is set correctly. I checked permissions and even changed them to -rwxrwxrwx but still get the same error (actually it would not work with absolute path if this were the problem, and it does).

    Any clues on what may be going on?

    Cheers!



  • Maybe you just cannot write into your executable? That might throw off addresses and render your application useless.
    I am only assuming, though, since I have never tried to use a resource file for writing.



  • When I use a .qrc file, I changed the prefix to / so when I want any of the files it is just ":/filename".

    not sure if this is the issues but is the prefix "/config/" or "/config"?


  • Lifetime Qt Champion

    Hi,

    Resources files are read-only (and they are compiled in your binary executable).

    If you need a read-write solution, you should copy the resource file somewhere (QStandardPaths comes to mind) and use that file instead.



  • Ah... ok. Thanks a lot!


Log in to reply
 

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