diff options
author | Fawzi Mohamed <fawzi.mohamed@qt.io> | 2020-06-15 08:24:33 +0200 |
---|---|---|
committer | Fawzi Mohamed <fawzi.mohamed@qt.io> | 2020-08-27 10:21:26 +0200 |
commit | 0028b176981b4ac2361b2d377b478791b0d40d4f (patch) | |
tree | 1ba02970ec70f7e9442f775f3a3c60c33ae554d9 /src/qmltyperegistrar | |
parent | 16613f3741af013f7e380c98df6889d73512d0ad (diff) |
import Qt namespace in QtQml
Introduces and uses the QML_FOREIGN_NAMESPACE to declare the Qt namespace in QtQml, and exports all the enumerations
in the Qt namespace, and makes them available also in QtQml/plugins.qmltypes
Please note that this does *not* remove the special QV4::QtObject
as it contains much more than the enumerations.
Having two object registered as Qt (the complete QV4::QtObject added
to the global properties in ExecutionEngine::initializeGlobal, and
QtInQml registered by the qmltyperegistrar) gives problems, if the
partial one overrides the complete one.
For this reason the classinfo QML.ManualRegistration (no public macro
until shown to be more generally useful) is introduced and
used to ensure that QtInQml generates only documentation
(plugins.qmltypes), and no registration that might conflict with
QtObject.
This makes the current builtins.qmltypes redundant.
Fixes: QTBUG-84897
Change-Id: Iffc96cd3e1d9f9d7d047ee60221a4b0928f53005
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmltyperegistrar')
-rw-r--r-- | src/qmltyperegistrar/qmltyperegistrar.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/qmltyperegistrar/qmltyperegistrar.cpp b/src/qmltyperegistrar/qmltyperegistrar.cpp index fafe594edb..c2918e515e 100644 --- a/src/qmltyperegistrar/qmltyperegistrar.cpp +++ b/src/qmltyperegistrar/qmltyperegistrar.cpp @@ -355,7 +355,14 @@ int main(int argc, char **argv) qPrintable(include)); } includes.append(include); - classDef.insert(QLatin1String("registerable"), true); + { + bool shouldRegister = true; + for (const QJsonValue &v : classDef.value(QLatin1String("classInfos")).toArray()) { + if (v[QLatin1String("name")].toString() == QLatin1String("QML.ManualRegistration")) + shouldRegister = QStringView(u"true").compare(v[QLatin1String("value")].toString(), Qt::CaseInsensitive) != 0; + } + classDef.insert(QLatin1String("registerable"), shouldRegister); + } types.append(classDef); break; @@ -427,8 +434,13 @@ int main(int argc, char **argv) const QString className = classDef[QLatin1String("qualifiedClassName")].toString(); if (classDef.value(QLatin1String("namespace")).toBool()) { - fprintf(output, "\n qmlRegisterNamespaceAndRevisions(&%s::staticMetaObject, \"%s\", %s);", - qPrintable(className), qPrintable(module), qPrintable(majorVersion)); + QString targetName = className; + for (const QJsonValue &v : classDef.value(QLatin1String("classInfos")).toArray()) { + if (v[QLatin1String("name")].toString() == QLatin1String("QML.Foreign")) + targetName = v[QLatin1String("value")].toString(); + } + fprintf(output, "\n qmlRegisterNamespaceAndRevisions(&%s::staticMetaObject, \"%s\", %s, nullptr, &%s::staticMetaObject);", + qPrintable(targetName), qPrintable(module), qPrintable(majorVersion), qPrintable(className)); } else { fprintf(output, "\n qmlRegisterTypesAndRevisions<%s>(\"%s\", %s);", qPrintable(className), qPrintable(module), qPrintable(majorVersion)); |