0

Problem description:

In Qt5, it was straightforward to work with QML resources in a static library. We simply created a .qrc file to include the QML files along with a qmldir, set QML_IMPORT_PATH for detection in Qt Creator, and used the Q_INIT_RESOURCE macro to initialize resources at runtime.

However, in Qt6, with the introduction of new patches and changes in the CMake workflow, we now need to use the qt_add_qml_module function to generate a .qrc file for QML files.

I also found the generated qrc file and CPP-initialize file. Both files not use the Q_INIT_RESOURCE macros. Which suggests that in a static build, the resources will not be loaded.

Automatically generated resource wrapper:

// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

// This file was generated by the qt_add_resources command.

#include <QtCore/qtsymbolmacros.h>

QT_DECLARE_EXTERN_RESOURCE(qmake_QEQuick3d)

namespace {
    struct resourceReferenceKeeper {
        resourceReferenceKeeper() { QT_KEEP_RESOURCE(qmake_QEQuick3d) }
    } resourceReferenceKeeperInstance;
}


Questions:

  • What steps should we take when working with a static library that includes QML files?
  • Specifically, where should we place the Q_INIT_RESOURCE macro in this new Qt6 setup?

If anyone has experience in packing qml in qt6 into a static library, please share.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.