Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmltcobjectcreationhelper.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
6
7#include <private/qqmlmetatype_p.h>
8#include <private/qmetaobjectbuilder_p.h>
9#include <private/qobject_p.h>
10#include <private/qqmltype_p_p.h>
11
13
14void qmltcCreateDynamicMetaObject(QObject *object, const QmltcTypeData &data)
15{
16 // TODO: when/if qmltc-compiled types would be registered via
17 // qmltyperegistrar, instead of creating a dummy QQmlTypePrivate, fetch the
18 // good QQmlType via QQmlMetaType::qmlType(). to do it correctly, one needs,
19 // along with the meta object, module name and revision. all that should be
20 // available ahead-of-time to qmltc.
21 auto qmlTypePrivate = new QQmlTypePrivate(data.regType);
22
23 // tie qmlTypePrivate destruction to objects's destruction. the type's
24 // content is not needed once the associated object is deleted
25 QObject::connect(object, &QObject::destroyed, object,
26 [qmlTypePrivate](QObject *) { qmlTypePrivate->release(); },
27 Qt::DirectConnection);
28
29 // initialize QQmlType::QQmlCppTypeData
30 Q_ASSERT(data.regType == QQmlType::CppType);
31 qmlTypePrivate->extraData.cppTypeData->allocationSize = data.allocationSize;
32 qmlTypePrivate->extraData.cppTypeData->newFunc = nullptr;
33 qmlTypePrivate->extraData.cppTypeData->userdata = nullptr;
34 qmlTypePrivate->extraData.cppTypeData->noCreationReason =
35 QStringLiteral("Qmltc-compiled type is not creatable via QQmlType");
36 qmlTypePrivate->extraData.cppTypeData->createValueTypeFunc = nullptr;
37 qmlTypePrivate->extraData.cppTypeData->parserStatusCast = -1;
38 qmlTypePrivate->extraData.cppTypeData->extFunc = nullptr;
39 qmlTypePrivate->extraData.cppTypeData->extMetaObject = nullptr;
40 qmlTypePrivate->extraData.cppTypeData->customParser = nullptr;
41 qmlTypePrivate->extraData.cppTypeData->attachedPropertiesFunc = nullptr;
42 qmlTypePrivate->extraData.cppTypeData->attachedPropertiesType = nullptr;
43 qmlTypePrivate->extraData.cppTypeData->propertyValueSourceCast = -1;
44 qmlTypePrivate->extraData.cppTypeData->propertyValueInterceptorCast = -1;
45 qmlTypePrivate->extraData.cppTypeData->finalizerCast = -1;
46 qmlTypePrivate->extraData.cppTypeData->registerEnumClassesUnscoped = false;
47 qmlTypePrivate->extraData.cppTypeData->registerEnumsFromRelatedTypes = false;
48
49 qmlTypePrivate->baseMetaObject = data.metaObject;
50
51 QQmlType qmlType(qmlTypePrivate);
52 Q_ASSERT(qmlType.isValid());
53
54 QObjectPrivate *op = QObjectPrivate::get(object);
55 // ### inefficient - rather, call this function only once for the leaf type
56 if (op->metaObject) {
57 delete op->metaObject;
58 op->metaObject = nullptr;
59 }
60
61 qmlType.createProxy(object);
62}
63
64QT_END_NAMESPACE
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE void qmltcCreateDynamicMetaObject(QObject *object, const QmltcTypeData &data)