summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2022-06-17 12:17:44 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2022-06-22 01:12:57 +0200
commitdd12c79bc29394245672f3dc17db788a33bbfe31 (patch)
treed8bd6db7f267a4ceed504de6bb083ea38e37da1a
parent2d9b8e6b4310fd6c4f8f5c88e4982ad73bf83d9a (diff)
Fix Qt3D.Core type registration to be called in static builds
The automatically generated type registrations function qml_register_types_Qt3D_Core was not called in static builds, because the quick3dcoreplugin target is using a custom qt3dquick3dcoreplugin.cpp file instead of an auto-generated one. Types were found correctly in a shared Qt build because the 3DQuick backing library was loaded by the dynamic plugin at runtime and the static initializer calling qml_register_types_Qt3D_Core was executed. In a static build, the linker would discard the qml_register_types_Qt3D_Core function (and the static initializer) because nothing was referencing it. Modify qt3dquick3dcoreplugin.cpp to manually reference the type registration file, just like an auto-generated source file would do it. A Q_IMPORT_PLUGIN(Qt3DQuick3DCorePlugin) which is link directly to applications via an object file then ensures that registrations succeeds. Compared to 6.4, the type registration symbol lives outside of QT_BEGIN_NAMESPACE because e2b4226abfb1f1b43f8ecc5f9df40787e3d574b6 was not picked for < 6.4. Amends 59fc9cacce5eca68c9dece3c30d6f11ee7693d4e Fixes: QTBUG-102328 Change-Id: I371b272c7c3a1d21aeeb68f45a26e4186c39c5c9 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> (cherry picked from commit 57fbc3b60f6ade591713092a723dcf696ced734b)
-rw-r--r--src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp10
-rw-r--r--src/quick3d/imports/core/qt3dquick3dcoreplugin.h2
2 files changed, 11 insertions, 1 deletions
diff --git a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
index 14987e764..de476918d 100644
--- a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
+++ b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
@@ -62,8 +62,18 @@
#include <QtQml/qqml.h>
+extern void qml_register_types_Qt3D_Core();
+Q_GHS_KEEP_REFERENCE(qml_register_types_Qt3D_Core);
+
QT_BEGIN_NAMESPACE
+Qt3DQuick3DCorePlugin::Qt3DQuick3DCorePlugin(QObject *parent)
+ : QQmlExtensionPlugin(parent)
+{
+ volatile auto registration = &qml_register_types_Qt3D_Core;
+ Q_UNUSED(registration);
+}
+
void Qt3DQuick3DCorePlugin::registerTypes(const char *uri)
{
Q_UNUSED(uri);
diff --git a/src/quick3d/imports/core/qt3dquick3dcoreplugin.h b/src/quick3d/imports/core/qt3dquick3dcoreplugin.h
index afc092bbb..ebedb22a4 100644
--- a/src/quick3d/imports/core/qt3dquick3dcoreplugin.h
+++ b/src/quick3d/imports/core/qt3dquick3dcoreplugin.h
@@ -49,7 +49,7 @@ class Qt3DQuick3DCorePlugin : public QQmlExtensionPlugin
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
- Qt3DQuick3DCorePlugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) { }
+ Qt3DQuick3DCorePlugin(QObject *parent = nullptr);
~Qt3DQuick3DCorePlugin();
void registerTypes(const char *uri) override;
};