Important: Please read the Qt Code of Conduct -

QResource::registerResource and "mapRoot"

  • Hey

    I'm experiencing a weird behaviour with QResource::registerResource, using the second argument "mapRoot".

    "QResource::registerResource(const QString & rccFileName, const QString & mapRoot = QString()) "

    Not sure if it is the expected way it should work, but when I'm trying to mount a dynamic resource file at the location specified by mapRoot, registerResource is registering my data at ":/" as well.

    This is a problem for me because I have others resources registered at ":/" and I don't want them to collide with the newly registered resources I'm trying to load. The documentation is not crystal clear about this behaviour.

    Here is a test code:

    qDebug() << QResource::registerResource("test.rcc", "/foo/bar");
    qDebug() << ":/img/Dealer :" << QFile::exists(":/img/Dealer");
    qDebug() << ":/foo/bar/img/Dealer :" << QFile::exists(":/foo/bar/img/Dealer");

    The output is:

    :/img/Dealer : true
    :/foo/bar/img/Dealer : true

    So my question is, is it the expected behaviour or something is buggy there ?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you by any chance also building that rcc file in your application ?

  • Hi and Thank you,

    No i'm building it apart with rcc -o, it's not a part of my building chain at all.

  • Moderators

    But maybe you have it added to your .pro file under RESOURCES?

  • My main project where I spot the issue is managed with cmake, and I don't ask for any build-in resources.
    My test project (code above), is built with qmake, the .pro is pretty straightforward :

    QT += core

    QT -= gui

    TARGET = TestRegister
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

  • Moderators

    OK, that pretty much rules out the possibility that Qt automatically picked up your resource.

Log in to reply