QML files not found when deploying on Mac



  • The Qt Creator log shows this when trying to run a Mac QML app:

    project.app/Contents/MacOS/main.qml:-1 File not found

    There is no scenario I can find where the qml files would end up in this directory in a mac build. How have others set this up? The instructions on this page make it look so easy, but I suspect these instructions were not tried on Mac:

    https://qt-project.org/doc/qt-5.1/qtquickcontrols/qtquickcontrols-overview.html#setting-up-controls-from-c
    "Setting Up Controls under C++"

    They just list the qml file name and it works; but in my experience this is not so easy.

    I could try to use a resource file, however my qml has Image elements that interact image sources in the local filesystem, not in the build system. Putting qml in a resource file seems to require that any images loaded in qml are also in the relative path of the resource file.


  • Moderators

    This is true for every operating system, not only Mac: Qt does not manage the QML files for you, you need to do that part yourself. That means that if you are not happy with QRC, you need to deploy QML files by hand/ custom scripts.

    [quote]Putting qml in a resource file seems to require that any images loaded in qml are also in the relative path of the resource file.[/quote]

    True, but that behaviour can be changed with some hardcore hacking (need to reset the context). Example:
    @
    QQmlContext *context = engine()->contextForObject(object);
    context->setBaseUrl(QUrl::fromLocalFile("")); // This resets the QRC reading mode
    @



  • Hm, if I do not use a resource file and just use a simple setup like this:
    @
    QtQuick2ControlsApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/ajssg-view/main.qml"));
    viewer.show();@

    The qml is properly deployed.

    However as soon as I go to this, it does not work at all as smoothly (or for me yet, at all):
    @
    QApplication app(argc, argv);
    QQmlApplicationEngine engine(QUrl::fromLocalFile("main.qml"));
    return app.exec();@

    I've tried every conceivable path and expression for engine() constructor.


Log in to reply
 

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