Cannot import directory in resources

  • I have a qrc file which contains:


    When I write import "scene" in main.qml, it prints:

    QQmlApplicationEngine failed to load component
    file::/qml/main.qml:19 import "scene" has no qmldir and no namespace

    If I change import "scene" to import "qrc:/qml/scene", it just works fine.
    But this is very annoying because whenever importing directory, it makes me write full absolute directory path.
    Futhermore, I'm using qrc file only for releasing and I don't use qrc file during developing/debugging.
    If I have to write always absolute path for QML file in resources, I have to write two sets of QML file which differ for only import statements.

    How can I make import "scene" work with QML file in qrc file here?

    FYI, I've tried to add /qml/scene/qmldir file but it didn't work.

  • Moderators

    QML engine assumes the loading source base on how you call QQmlEngine::load(). If you use QRC there, it will be used for all import statements in QML, too. If you use relative path in load(), it will use relative paths in QML as well. If you use shadow building (the default), it means that it will look for "scene" directory in your build dir.

    Hope it helps :-) There is also a way to disable QRC temporarily, I've described it here: link.

    I do recommend, however, to use QRC both for production and development - you'll have no issues at all :-)

Log in to reply

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