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:
If anyone has experience in packing qml in qt6 into a static library, please share.