Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmlcomponent.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
4#include "qqmlcomponent.h"
5#include "qqmlcomponent_p.h"
7
8#include "qqmlengine_p.h"
9#include "qqmlvme_p.h"
10#include "qqml.h"
11#include "qqmlengine.h"
12#include "qqmlincubator.h"
13#include "qqmlincubator_p.h"
14#include <private/qqmljavascriptexpression_p.h>
15#include <private/qqmlsourcecoordinate_p.h>
16
17#include <private/qv4functionobject_p.h>
18#include <private/qv4script_p.h>
19#include <private/qv4scopedvalue_p.h>
20#include <private/qv4objectiterator_p.h>
21#include <private/qv4qobjectwrapper_p.h>
22#include <private/qv4jscall_p.h>
23
24#include <QDir>
25#include <QStack>
26#include <QStringList>
27#include <QThreadStorage>
28#include <QtCore/qdebug.h>
29#include <QtCore/qloggingcategory.h>
30#include <qqmlinfo.h>
31
32
33using namespace Qt::Literals::StringLiterals;
34
35namespace {
36 Q_CONSTINIT thread_local int creationDepth = 0;
37}
38
39Q_LOGGING_CATEGORY(lcQmlComponentGeneral, "qt.qml.qmlcomponent")
40
42
43class QQmlComponentExtension : public QV4::ExecutionEngine::Deletable
44{
45public:
48
50};
52
278{
279 Q_Q(QQmlComponent);
280
282
284 typeData.reset();
285 progress = 1.0;
286
287 emit q->statusChanged(q->status());
288 emit q->progressChanged(progress);
289}
290
292{
293 Q_Q(QQmlComponent);
294
295 progress = p;
296
297 emit q->progressChanged(p);
298}
299
300void QQmlComponentPrivate::fromTypeData(const QQmlRefPointer<QQmlTypeData> &data)
301{
302 url = data->finalUrl();
303 if (auto cu = data->compilationUnit())
305
306 if (!compilationUnit) {
307 Q_ASSERT(data->isError());
308 state.errors.clear();
309 state.appendErrors(data->errors());
310 }
311}
312
317
319{
320 if (typeData) {
322 typeData.reset();
323 }
324
326 loadedType = {};
327 inlineComponentName.reset();
328}
329
331{
332 if (!engine) {
333 // ###Qt6: In Qt 6, it should be impossible for users to create a QQmlComponent without an engine, and we can remove this check
334 qWarning("QQmlComponent: Must provide an engine before calling create");
335 return nullptr;
336 }
337 if (!context)
339 return q->beginCreate(context);
340}
341
343 QV4::Value *object, const QString &propertyName, QQmlObjectCreator *creator)
344{
345 if (!creator)
346 return;
347
349 if (!wrapper)
350 return;
351
352 QObject *o = wrapper->object();
353 if (!o)
354 return;
355
356 if (QQmlData *ddata = QQmlData::get(o)) {
357 const QQmlPropertyData *propData = ddata->propertyCache->property(
358 propertyName, o, ddata->outerContext);
359 if (propData && propData->isBindable())
360 creator->removePendingBinding(o, propData->coreIndex());
361 return;
362 }
363
364 const QMetaObject *meta = o->metaObject();
365 Q_ASSERT(meta);
366 const int index = meta->indexOfProperty(propertyName.toUtf8());
367 if (index != -1 && meta->property(index).isBindable())
368 creator->removePendingBinding(o, index);
369}
370
372 QObject *base, const QString &name, const QVariant &value)
373{
374 const QStringList properties = name.split(u'.');
375
376 if (properties.size() > 1) {
377 QV4::Scope scope(engine->handle());
380
381 for (int i = 0; i < properties.size() - 1; ++i) {
382 segment = scope.engine->newString(properties.at(i));
383 object = object->get(segment);
384 if (scope.engine->hasException)
385 break;
386 }
387 const QString lastProperty = properties.last();
388 segment = scope.engine->newString(lastProperty);
389 object->put(segment, scope.engine->metaTypeToJS(value.metaType(), value.constData()));
390 if (scope.engine->hasException) {
392 scope.engine->hasException = false;
393 return false;
394 }
395
396 removePendingQPropertyBinding(object, lastProperty, state.creator());
397 return true;
398 }
399
400 QQmlProperty prop;
404 else
405 prop = QQmlProperty(base, name, engine);
407 const bool isValid = prop.isValid();
408 if (isValid && privProp->writeValueProperty(value, {})) {
409 if (prop.isBindable()) {
411 creator->removePendingBinding(prop.object(), prop.index());
412 }
413 } else {
415 error.setUrl(url);
416 if (isValid) {
417 error.setDescription(QStringLiteral("Could not set initial property %1").arg(name));
418 } else {
419 error.setDescription(QStringLiteral("Setting initial properties failed: "
420 "%2 does not have a property called %1")
422 }
424 return false;
425 }
426
427 return true;
428
429}
430
435 : QObject(*(new QQmlComponentPrivate), parent)
436{
437}
438
443{
444 Q_D(QQmlComponent);
445
446 if (d->state.isCompletePending()) {
447 qWarning("QQmlComponent: Component destroyed while completion pending");
448
449 if (isError()) {
450 qWarning() << "This may have been caused by one of the following errors:";
451 for (const QQmlComponentPrivate::AnnotatedQmlError &e : std::as_const(d->state.errors))
452 qWarning().nospace().noquote() << QLatin1String(" ") << e.error;
453 }
454
455 // we might not have the creator anymore if the engine is gone
456 if (d->state.hasCreator())
457 d->completeCreate();
458 }
459
460 if (d->typeData) {
461 d->typeData->unregisterCallback(d);
462 d->typeData.reset();
463 }
464}
465
484{
485 Q_D(const QQmlComponent);
486
487 if (d->typeData)
488 return Loading;
489 else if (!d->state.errors.isEmpty())
490 return Error;
491 else if (d->engine && (d->compilationUnit || d->loadedType.isValid()))
492 return Ready;
493 else
494 return Null;
495}
496
501{
502 return status() == Null;
503}
504
509{
510 return status() == Ready;
511}
512
517{
518 return status() == Error;
519}
520
525{
526 return status() == Loading;
527}
528
536{
537 Q_D(const QQmlComponent);
538 return d->isBound();
539}
540
553{
554 Q_D(const QQmlComponent);
555 return d->progress;
556}
557
577 : QObject(*(new QQmlComponentPrivate), parent)
578{
579 Q_D(QQmlComponent);
580 d->engine = engine;
582 d->state.clear();
583 d->engine = nullptr;
584 });
585}
586
596 : QQmlComponent(engine, url, QQmlComponent::PreferSynchronous, parent)
597{
598}
599
610 QObject *parent)
611 : QQmlComponent(engine, parent)
612{
613 Q_D(QQmlComponent);
614 d->loadUrl(url, mode);
615}
616
631
646
654 QObject *parent)
655 : QQmlComponent(engine, fileName, QQmlComponent::PreferSynchronous, parent)
656{
657}
658
668 : QQmlComponent(engine, parent)
669{
670 Q_D(QQmlComponent);
671 if (fileName.startsWith(u':'))
672 d->loadUrl(QUrl(QLatin1String("qrc") + fileName), mode);
675 else
676 d->loadUrl(QUrl(fileName), mode);
677}
678
683 int start, QObject *parent)
684 : QQmlComponent(engine, parent)
685{
686 Q_D(QQmlComponent);
687 d->compilationUnit.reset(compilationUnit);
688 d->start = start;
689 d->url = compilationUnit->finalUrl();
690 d->progress = 1.0;
691}
692
699{
700 Q_D(QQmlComponent);
701
702 if (!d->engine) {
703 // ###Qt6: In Qt 6, it should be impossible for users to create a QQmlComponent without an engine, and we can remove this check
704 qWarning("QQmlComponent: Must provide an engine before calling setData");
705 return;
706 }
707
708 d->clear();
709
710 d->url = url;
711
712 QQmlRefPointer<QQmlTypeData> typeData = QQmlEnginePrivate::get(d->engine)->typeLoader.getType(data, url);
713
714 if (typeData->isCompleteOrError()) {
715 d->fromTypeData(typeData);
716 } else {
717 d->typeData = typeData;
718 d->typeData->registerCallback(d);
719 }
720
721 d->progress = 1.0;
723 emit progressChanged(d->progress);
724}
725
731{
732 Q_D(const QQmlComponent);
733 if (!d->creationContext.isNull())
734 return d->creationContext->asQQmlContext();
735
736 return qmlContext(this);
737}
738
745{
746 Q_D(const QQmlComponent);
747 return d->engine;
748}
749
756{
757 Q_D(QQmlComponent);
758 d->loadUrl(url);
759}
760
768{
769 Q_D(QQmlComponent);
770 d->loadUrl(url, mode);
771}
772
774{
775 Q_Q(QQmlComponent);
776 clear();
777
778 if (newUrl.isRelative()) {
779 // The new URL is a relative URL like QUrl("main.qml").
780 url = engine->baseUrl().resolved(QUrl(newUrl.toString()));
781 } else if (engine->baseUrl().isLocalFile() && newUrl.isLocalFile() && !QDir::isAbsolutePath(newUrl.toLocalFile())) {
782 // The new URL is a file on disk but it's a relative path; e.g.:
783 // QUrl::fromLocalFile("main.qml") or QUrl("file:main.qml")
784 // We need to remove the scheme so that it becomes a relative URL with a relative path:
785 QUrl fixedUrl(newUrl);
786 fixedUrl.setScheme(QString());
787 // Then, turn it into an absolute URL with an absolute path by resolving it against the engine's baseUrl().
788 // This is a compatibility hack for QTBUG-58837.
789 url = engine->baseUrl().resolved(fixedUrl);
790 } else {
791 url = newUrl;
792 }
793
794 if (newUrl.isEmpty()) {
796 error.setDescription(QQmlComponent::tr("Invalid empty URL"));
797 state.errors.emplaceBack(error);
798 return;
799 }
800
801 if (progress != 0.0) {
802 progress = 0.0;
803 emit q->progressChanged(progress);
804 }
805
809 QQmlRefPointer<QQmlTypeData> data = QQmlEnginePrivate::get(engine)->typeLoader.getType(url, loaderMode);
810
811 if (data->isCompleteOrError()) {
813 progress = 1.0;
814 } else {
815 typeData = data;
817 progress = data->progress();
818 }
819
820 emit q->statusChanged(q->status());
821 if (progress != 0.0)
822 emit q->progressChanged(progress);
823}
824
829QList<QQmlError> QQmlComponent::errors() const
830{
831 Q_D(const QQmlComponent);
832 QList<QQmlError> errors;
833 errors.reserve(d->state.errors.size());
834 for (const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->state.errors)
835 errors.emplaceBack(annotated.error);
836 return errors;
837}
838
855{
856 Q_D(const QQmlComponent);
857 QString ret;
858 if(!isError())
859 return ret;
860 for (const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->state.errors) {
861 const QQmlError &e = annotated.error;
862 ret += e.url().toString() + QLatin1Char(':') +
863 QString::number(e.line()) + QLatin1Char(' ') +
864 e.description() + QLatin1Char('\n');
865 }
866 return ret;
867}
868
880{
881 Q_D(const QQmlComponent);
882 return d->url;
883}
884
889 : QObject(dd, parent)
890{
891}
892
910{
911 Q_D(QQmlComponent);
912 return d->createWithProperties(nullptr, QVariantMap {}, context);
913}
914
931{
932 Q_D(QQmlComponent);
933 return d->createWithProperties(nullptr, initialProperties, context);
934}
935
936static void QQmlComponent_setQmlParent(QObject *me, QObject *parent); // forward declaration
937
942{
943 Q_Q(QQmlComponent);
944
946 if (!rv) {
947 if (state.isCompletePending()) {
948 // overridden completCreate might assume that
949 // the object has actually been created
950 ++creationDepth;
952 complete(ep, &state);
953 --creationDepth;
954 }
955 return nullptr;
956 }
957
958 QQmlComponent_setQmlParent(rv, parent); // internally checks if parent is nullptr
959
960 q->setInitialProperties(rv, properties);
961 q->completeCreate();
962
964 if (behavior == CreateWarnAboutRequiredProperties) {
965 for (const auto &unsetRequiredProperty : std::as_const(*state.requiredProperties())) {
966 const QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
967 qmlWarning(rv, error);
968 }
969 }
970 delete rv;
971 rv = nullptr;
972 }
973 return rv;
974}
975
1019
1020QObject *QQmlComponentPrivate::beginCreate(QQmlRefPointer<QQmlContextData> context)
1021{
1022 Q_Q(QQmlComponent);
1023 auto cleanup = qScopeGuard([this] {
1024 if (!state.errors.isEmpty() && lcQmlComponentGeneral().isDebugEnabled()) {
1025 for (const auto &e : std::as_const(state.errors)) {
1026 qCDebug(lcQmlComponentGeneral) << "QQmlComponent: " << e.error.toString();
1027 }
1028 }
1029 });
1030 if (!context) {
1031 qWarning("QQmlComponent: Cannot create a component in a null context");
1032 return nullptr;
1033 }
1034
1035 if (!context->isValid()) {
1036 qWarning("QQmlComponent: Cannot create a component in an invalid context");
1037 return nullptr;
1038 }
1039
1040 if (context->engine() != engine) {
1041 qWarning("QQmlComponent: Must create component in context from the same QQmlEngine");
1042 return nullptr;
1043 }
1044
1045 if (state.isCompletePending()) {
1046 qWarning("QQmlComponent: Cannot create new component instance before completing the previous");
1047 return nullptr;
1048 }
1049
1050 // filter out temporary errors as they do not really affect component's
1051 // state (they are not part of the document compilation)
1052 state.errors.removeIf([](const auto &e) { return e.isTransient; });
1054
1055 if (!q->isReady()) {
1056 qWarning("QQmlComponent: Component is not ready");
1057 return nullptr;
1058 }
1059
1060 // Do not create infinite recursion in object creation
1061 static const int maxCreationDepth = 10;
1062 if (creationDepth >= maxCreationDepth) {
1063 qWarning("QQmlComponent: Component creation is recursing - aborting");
1064 return nullptr;
1065 }
1066
1068
1069 enginePriv->inProgressCreations++;
1070 state.errors.clear();
1072
1073 QObject *rv = nullptr;
1074
1075 if (!loadedType.isValid()) {
1076 enginePriv->referenceScarceResources();
1078
1080 if (const QString *icName = inlineComponentName.get()) {
1082 if (start == -1)
1084 Q_ASSERT(start > 0);
1085 } else {
1087 }
1088
1089 rv = state.creator()->create(start, nullptr, nullptr, flags);
1090 if (!rv)
1092 enginePriv->dereferenceScarceResources();
1093 } else {
1094 // TODO: extract into function
1097 QQmlParserStatus *parserStatus = nullptr;
1098 const int parserStatusCast = loadedType.parserStatusCast();
1099 if (parserStatusCast != -1) {
1100 parserStatus = reinterpret_cast<QQmlParserStatus*>(reinterpret_cast<char *>(rv) + parserStatusCast);
1101 parserStatus->classBegin();
1102 }
1103 for (int i = 0, propertyCount = propertyCache->propertyCount(); i < propertyCount; ++i) {
1104 if (const QQmlPropertyData *propertyData = propertyCache->property(i); propertyData->isRequired()) {
1107 info.propertyName = propertyData->name(rv);
1108 state.addPendingRequiredProperty(rv, propertyData, info);
1109 }
1110 }
1111 if (parserStatus)
1112 parserStatus->componentComplete();
1113 if (const int finalizerCast = loadedType.finalizerCast(); finalizerCast != -1) {
1114 auto* hook = reinterpret_cast<QQmlFinalizerHook *>(reinterpret_cast<char *>(rv) + finalizerCast);
1115 hook->componentFinalized();
1116 }
1117 }
1118
1119 if (rv) {
1120 QQmlData *ddata = QQmlData::get(rv);
1121 Q_ASSERT(ddata);
1122 // top-level objects should never get JS ownership.
1123 // if JS ownership is needed this needs to be explicitly undone (like in createObject())
1124 ddata->indestructible = true;
1125 ddata->explicitIndestructibleSet = true;
1126 ddata->rootObjectInCreation = false;
1127 }
1128
1129 return rv;
1130}
1131
1133 QObject *object, DeferredState *deferredState)
1134{
1135 QQmlData *ddata = QQmlData::get(object);
1136 Q_ASSERT(!ddata->deferredData.isEmpty());
1137
1138 deferredState->reserve(ddata->deferredData.size());
1139
1140 for (QQmlData::DeferredData *deferredData : std::as_const(ddata->deferredData)) {
1141 enginePriv->inProgressCreations++;
1142
1145
1146 auto creator = state.initCreator(
1147 deferredData->context->parent(),
1148 deferredData->compilationUnit,
1149 QQmlRefPointer<QQmlContextData>());
1150
1151 if (!creator->populateDeferredProperties(object, deferredData))
1153 deferredData->bindings.clear();
1154
1155 deferredState->push_back(std::move(state));
1156 }
1157}
1158
1160{
1161 for (ConstructionState &state : *deferredState)
1162 complete(enginePriv, &state);
1163}
1164
1166{
1167 if (state->isCompletePending()) {
1169 state->creator()->finalize(interrupt);
1170
1171 state->setCompletePending(false);
1172
1173 enginePriv->inProgressCreations--;
1174
1175 if (0 == enginePriv->inProgressCreations) {
1176 while (enginePriv->erroredBindings) {
1177 enginePriv->warning(enginePriv->erroredBindings->removeError());
1178 }
1179 }
1180 }
1181}
1182
1201 QObject *createdComponent, const QString &name, RequiredProperties *requiredProperties,
1202 QQmlEngine *engine, bool *wasInRequiredProperties)
1203{
1204 Q_ASSERT(requiredProperties);
1205 QQmlProperty prop(createdComponent, name, engine);
1206 auto privProp = QQmlPropertyPrivate::get(prop);
1207 if (prop.isValid()) {
1208 // resolve outstanding required properties
1209 const QQmlPropertyData *targetProp = &privProp->core;
1210 if (targetProp->isAlias()) {
1211 auto target = createdComponent;
1212 QQmlPropertyIndex originalIndex(targetProp->coreIndex());
1213 QQmlPropertyIndex propIndex;
1214 QQmlPropertyPrivate::findAliasTarget(target, originalIndex, &target, &propIndex);
1216 Q_ASSERT(data && data->propertyCache);
1217 targetProp = data->propertyCache->property(propIndex.coreIndex());
1218 } else {
1219 // we need to get the pointer from the property cache instead of directly using
1220 // targetProp else the lookup will fail
1221 QQmlData *data = QQmlData::get(createdComponent);
1222 Q_ASSERT(data && data->propertyCache);
1223 targetProp = data->propertyCache->property(targetProp->coreIndex());
1224 }
1225 auto it = requiredProperties->constFind({createdComponent, targetProp});
1226 if (it != requiredProperties->cend()) {
1227 if (wasInRequiredProperties)
1228 *wasInRequiredProperties = true;
1229 requiredProperties->erase(it);
1230 } else {
1231 if (wasInRequiredProperties)
1232 *wasInRequiredProperties = false;
1233 }
1234 }
1235 return prop;
1236}
1237
1249{
1250 Q_D(QQmlComponent);
1251
1252 d->completeCreate();
1253}
1254
1256{
1258 for (const auto& unsetRequiredProperty: std::as_const(*state.requiredProperties())) {
1259 QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1261 }
1262 }
1263 if (loadedType.isValid()) {
1264 /*
1265 We can directly set completePending to false, as finalize is only concerned
1266 with setting up pending bindings, but that cannot happen here, as we're
1267 dealing with a pure C++ type, which cannot have pending bindings
1268 */
1270 QQmlEnginePrivate::get(engine)->inProgressCreations--;
1271 } else if (state.isCompletePending()) {
1272 ++creationDepth;
1274 complete(ep, &state);
1275 --creationDepth;
1276 }
1277}
1278
1280: QObject(parent), m_prev(nullptr), m_next(nullptr)
1281{
1282}
1283
1285{
1286 if (m_prev) *m_prev = m_next;
1287 if (m_next) m_next->m_prev = m_prev;
1288 m_prev = nullptr;
1289 m_next = nullptr;
1290}
1291
1296{
1298
1300 if (!engine)
1301 return a;
1302
1304 if (p->activeObjectCreator) { // XXX should only be allowed during begin
1305 a->insertIntoList(p->activeObjectCreator->componentAttachment());
1306 } else {
1308 Q_ASSERT(d);
1309 Q_ASSERT(d->context);
1310 d->context->addComponentAttached(a);
1311 }
1312
1313 return a;
1314}
1315
1335{
1336 Q_D(QQmlComponent);
1337 auto [status, type] = d->prepareLoadFromModule(uri, typeName);
1338 d->completeLoadFromModule(uri, typeName, type, status, mode);
1339}
1340
1343{
1344 auto enginePriv = QQmlEnginePrivate::get(engine);
1345 // LoadHelper must be on the Heap as it derives from QQmlRefCount
1346 auto loadHelper = QQml::makeRefPointer<LoadHelper>(&enginePriv->typeLoader, uri);
1347
1348 return loadHelper->resolveType(typeName);
1349}
1350
1354{
1355 Q_Q(QQmlComponent);
1356
1357 // we always mimic the progressChanged behavior from loadUrl
1358 auto reportError = [&](QString msg) {
1360 error.setDescription(msg);
1361 state.errors.push_back(std::move(error));
1362 progress = 1;
1363 emit q->progressChanged(1);
1364 emit q->statusChanged(q->Error);
1365 };
1366 auto emitProgressReset = [&](){
1367 if (progress != 0) {
1368 progress = 0;
1369 emit q->progressChanged(0);
1370 }
1371 };
1372 auto emitComplete = [&]() {
1373 progress = 1;
1374 emit q->progressChanged(1);
1375 emit q->statusChanged(q->status());
1376 };
1377 emitProgressReset();
1378 if (moduleStatus == LoadHelper::ResolveTypeResult::NoSuchModule) {
1379 reportError(QLatin1String(R"(No module named "%1" found)").arg(uri.toString()));
1380 } else if (!type.isValid()) {
1381 reportError(QLatin1String(R"(Module "%1" contains no type named "%2")")
1382 .arg(uri.toString(), typeName.toString()));
1383 } else if (type.isCreatable()) {
1384 clear();
1385 loadedType = type;
1386 emitComplete();
1387 } else if (type.isComposite()) {
1388 // loadUrl takes care of signal emission
1389 loadUrl(type.sourceUrl(), mode);
1390 } else if (type.isInlineComponentType()) {
1391 auto baseUrl = type.sourceUrl();
1393 {
1394 // we don't want to emit status changes from the "helper" loadUrl below
1395 // because it would signal success to early
1397 // we really need to continue in a synchronous way, otherwise we can't check the CU
1399 }
1400 if (q->isError()) {
1401 emitComplete();
1402 return;
1403 }
1404 QString elementName = type.elementName();
1405 if (compilationUnit->inlineComponentId(elementName) == -1) {
1406 QString realTypeName = typeName.toString();
1407 realTypeName.truncate(realTypeName.indexOf(u'.'));
1408 QString errorMessage = R"(Type "%1" from module "%2" contains no inline component named "%3".)"_L1.arg(
1409 realTypeName, uri.toString(), elementName);
1410 if (elementName == u"qml")
1411 errorMessage += " To load the type \"%1\", drop the \".qml\" extension."_L1.arg(realTypeName);
1412 reportError(std::move(errorMessage));
1413 } else {
1414 inlineComponentName = std::make_unique<QString>(std::move(elementName));
1415 emitComplete();
1416 }
1417 } else if (type.isSingleton() || type.isCompositeSingleton()) {
1418 reportError(QLatin1String(R"(%1 is a singleton, and cannot be loaded)").arg(typeName.toString()));
1419 } else {
1420 reportError(QLatin1String("Could not load %1, as the type is uncreatable").arg(typeName.toString()));
1421 }
1422}
1423
1445{
1446 Q_D(QQmlComponent);
1447
1448 if (!context)
1449 context = d->engine->rootContext();
1450
1451 QQmlRefPointer<QQmlContextData> contextData = QQmlContextData::get(context);
1452 QQmlRefPointer<QQmlContextData> forContextData =
1453 forContext ? QQmlContextData::get(forContext) : contextData;
1454
1455 if (!contextData->isValid()) {
1456 qWarning("QQmlComponent: Cannot create a component in an invalid context");
1457 return;
1458 }
1459
1460 if (contextData->engine() != d->engine) {
1461 qWarning("QQmlComponent: Must create component in context from the same QQmlEngine");
1462 return;
1463 }
1464
1465 if (!isReady()) {
1466 qWarning("QQmlComponent: Component is not ready");
1467 return;
1468 }
1469
1470 incubator.clear();
1471 QExplicitlySharedDataPointer<QQmlIncubatorPrivate> p(incubator.d);
1472
1473 if (d->loadedType.isValid()) {
1474 // there isn't really an incubation process for C++ backed types
1475 // so just create the object and signal that we are ready
1476
1477 p->incubateCppBasedComponent(this, context);
1478 return;
1479 }
1480
1481 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(d->engine);
1482
1483 p->compilationUnit = d->compilationUnit;
1484 p->enginePriv = enginePriv;
1485 p->creator.reset(new QQmlObjectCreator(contextData, d->compilationUnit, d->creationContext, p.data()));
1486 p->subComponentToCreate = d->start;
1487
1488 enginePriv->incubate(incubator, forContextData);
1489}
1490
1504{
1505 Q_D(QQmlComponent);
1506 for (auto it = properties.constBegin(); it != properties.constEnd(); ++it)
1507 d->setInitialProperty(component, it.key(), it.value());
1508}
1509
1510/*
1511 This is essentially a copy of QQmlComponent::create(); except it takes the QQmlContextData
1512 arguments instead of QQmlContext which means we don't have to construct the rather weighty
1513 wrapper class for every delegate item.
1514
1515 This is used by QQmlDelegateModel.
1516*/
1518 QQmlIncubator *incubationTask,
1521 const QQmlRefPointer<QQmlContextData> &context,
1522 const QQmlRefPointer<QQmlContextData> &forContext)
1523{
1524 QQmlIncubatorPrivate *incubatorPriv = QQmlIncubatorPrivate::get(incubationTask);
1527
1528 incubatorPriv->compilationUnit = componentPriv->compilationUnit;
1529 incubatorPriv->enginePriv = enginePriv;
1530 incubatorPriv->creator.reset(new QQmlObjectCreator(context, componentPriv->compilationUnit, componentPriv->creationContext));
1531
1532 if (start == -1) {
1533 if (const QString *icName = componentPriv->inlineComponentName.get()) {
1535 Q_ASSERT(start > 0);
1536 }
1537 }
1538 incubatorPriv->subComponentToCreate = componentPriv->start;
1539
1540 enginePriv->incubate(*incubationTask, forContext);
1541}
1542
1543
1544
1546
1547namespace QV4 {
1548
1549namespace Heap {
1550
1551#define QmlIncubatorObjectMembers(class, Member) \
1552 Member(class, HeapValue, HeapValue, valuemapOrObject) \
1553 Member(class, HeapValue, HeapValue, statusChanged) \
1554 Member(class, Pointer, QmlContext *, qmlContext) \
1555 Member(class, NoMark, QQmlComponentIncubator *, incubator) \
1556 Member(class, NoMark, QV4QPointer<QObject>, parent)
1557
1564
1565}
1566
1568{
1571
1572 static ReturnedValue method_get_statusChanged(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
1573 static ReturnedValue method_set_statusChanged(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
1574 static ReturnedValue method_get_status(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
1575 static ReturnedValue method_get_object(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
1576 static ReturnedValue method_forceCompletion(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
1577
1579 void setInitialState(QObject *, RequiredProperties *requiredProperties);
1580};
1581
1582}
1583
1585
1587{
1588public:
1589 QQmlComponentIncubator(QV4::Heap::QmlIncubatorObject *inc, IncubationMode mode)
1591 {
1592 incubatorObject.set(inc->internalClass->engine, inc);
1593 }
1594
1595 void statusChanged(Status s) override {
1598 i->statusChanged(s);
1599 }
1600
1601 void setInitialState(QObject *o) override {
1604 auto d = QQmlIncubatorPrivate::get(this);
1605 i->setInitialState(o, d->requiredProperties());
1606 }
1607
1608 QV4::PersistentValue incubatorObject; // keep a strong internal reference while incubating
1609};
1610
1611
1613{
1614 if (parent) {
1615 me->setParent(parent);
1617 QList<APF> functions = QQmlMetaType::parentFunctions();
1618
1619 bool needParent = false;
1620 for (int ii = 0; ii < functions.size(); ++ii) {
1621 QQmlPrivate::AutoParentResult res = functions.at(ii)(me, parent);
1622 if (res == QQmlPrivate::Parented) {
1623 needParent = false;
1624 break;
1625 } else if (res == QQmlPrivate::IncompatibleParent) {
1626 needParent = true;
1627 }
1628 }
1629 if (needParent)
1630 qmlWarning(me) << "Created graphical object was not placed in the graphics scene.";
1631 }
1632}
1633
1679 const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent,
1681{
1682 QV4::Scope scope(engine);
1684 QV4::ScopedObject valueMap(scope, v);
1686 QV4::ScopedString name(scope);
1687 QV4::ScopedValue val(scope);
1688 if (engine->hasException)
1689 return;
1690
1691 // js modules (mjs) have no qmlContext
1692 QV4::ScopedStackFrame frame(scope, qmlContext ? qmlContext : engine->scriptContext());
1693
1694 while (1) {
1695 name = it.nextPropertyNameAsString(val);
1696 if (!name)
1697 break;
1698 object = o;
1699 const QStringList properties = name->toQString().split(QLatin1Char('.'));
1700 bool isTopLevelProperty = properties.size() == 1;
1701 for (int i = 0; i < properties.size() - 1; ++i) {
1702 name = engine->newString(properties.at(i));
1703 object = object->get(name);
1704 if (engine->hasException || !object) {
1705 break;
1706 }
1707 }
1708 if (engine->hasException) {
1709 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1710 continue;
1711 }
1712 if (!object) {
1714 error.setUrl(qmlContext ? qmlContext->qmlContext()->url() : QUrl());
1715 error.setDescription(QLatin1String("Cannot resolve property \"%1\".")
1716 .arg(properties.join(u'.')));
1717 qmlWarning(createdComponent, error);
1718 continue;
1719 }
1720 const QString lastProperty = properties.last();
1721 name = engine->newString(lastProperty);
1722 object->put(name, val);
1723 if (engine->hasException) {
1724 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1725 continue;
1726 } else if (isTopLevelProperty && requiredProperties) {
1727 auto prop = removePropertyFromRequired(createdComponent, name->toQString(),
1728 requiredProperties, engine->qmlEngine());
1729 }
1730
1731 removePendingQPropertyBinding(object, lastProperty, creator);
1732 }
1733
1734 engine->hasException = false;
1735}
1736
1738{
1740 QString description = QLatin1String("Required property %1 was not initialized").arg(unsetRequiredProperty.propertyName);
1741 switch (unsetRequiredProperty.aliasesToRequired.size()) {
1742 case 0:
1743 break;
1744 case 1: {
1745 const auto info = unsetRequiredProperty.aliasesToRequired.first();
1746 description += QLatin1String("\nIt can be set via the alias property %1 from %2\n").arg(info.propertyName, info.fileUrl.toString());
1747 break;
1748 }
1749 default:
1750 description += QLatin1String("\nIt can be set via one of the following alias properties:");
1751 for (auto aliasInfo: unsetRequiredProperty.aliasesToRequired) {
1752 description += QLatin1String("\n- %1 (%2)").arg(aliasInfo.propertyName, aliasInfo.fileUrl.toString());
1753 }
1754 description += QLatin1Char('\n');
1755 }
1756 error.setDescription(description);
1757 error.setUrl(unsetRequiredProperty.fileUrl);
1758 error.setLine(qmlConvertSourceCoordinate<quint32, int>(
1759 unsetRequiredProperty.location.line()));
1760 error.setColumn(qmlConvertSourceCoordinate<quint32, int>(
1761 unsetRequiredProperty.location.column()));
1762 return error;
1763}
1764
1765#if QT_DEPRECATED_SINCE(6, 3)
1770{
1771 Q_D(QQmlComponent);
1772 Q_ASSERT(d->engine);
1773 Q_ASSERT(args);
1774
1775 qmlWarning(this) << "Unsuitable arguments passed to createObject(). The first argument should "
1776 "be a QObject* or null, and the second argument should be a JavaScript "
1777 "object or a QVariantMap";
1778
1779 QObject *parent = nullptr;
1780 QV4::ExecutionEngine *v4 = args->v4engine();
1781 QV4::Scope scope(v4);
1783
1784 if (args->length() >= 1) {
1785 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
1786 if (qobjectWrapper)
1787 parent = qobjectWrapper->object();
1788 }
1789
1790 if (args->length() >= 2) {
1791 QV4::ScopedValue v(scope, (*args)[1]);
1792 if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
1793 qmlWarning(this) << tr("createObject: value is not an object");
1794 args->setReturnValue(QV4::Encode::null());
1795 return;
1796 }
1797 valuemap = v;
1798 }
1799
1800 QQmlContext *ctxt = creationContext();
1801 if (!ctxt) ctxt = d->engine->rootContext();
1802
1803 QObject *rv = beginCreate(ctxt);
1804
1805 if (!rv) {
1806 args->setReturnValue(QV4::Encode::null());
1807 return;
1808 }
1809
1811
1813 Q_ASSERT(object->isObject());
1814
1815 if (!valuemap->isUndefined()) {
1818 v4, qmlContext, object, valuemap, d->state.requiredProperties(), rv,
1819 d->state.creator());
1820 }
1821 if (d->state.hasUnsetRequiredProperties()) {
1822 QList<QQmlError> errors;
1823 for (const auto &requiredProperty: std::as_const(*d->state.requiredProperties())) {
1825 }
1826 qmlWarning(rv, errors);
1827 args->setReturnValue(QV4::Encode::null());
1828 delete rv;
1829 return;
1830 }
1831
1832 d->completeCreate();
1833
1835 QQmlData::get(rv)->explicitIndestructibleSet = false;
1836 QQmlData::get(rv)->indestructible = false;
1837
1838 args->setReturnValue(object->asReturnedValue());
1839}
1840#endif
1841
1846{
1847 Q_D(QQmlComponent);
1848 Q_ASSERT(d->engine);
1849 QObject *rv = d->createWithProperties(parent, properties, creationContext(),
1851 if (rv) {
1852 QQmlData *qmlData = QQmlData::get(rv);
1853 Q_ASSERT(qmlData);
1854 qmlData->explicitIndestructibleSet = false;
1855 qmlData->indestructible = false;
1856 }
1857 return rv;
1858}
1859
1919{
1920 Q_D(QQmlComponent);
1921 Q_ASSERT(d->engine);
1922 Q_UNUSED(d);
1923 Q_ASSERT(args);
1924 QV4::ExecutionEngine *v4 = args->v4engine();
1925 QV4::Scope scope(v4);
1926
1927 QObject *parent = nullptr;
1930
1931 if (args->length() >= 1) {
1932 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
1933 if (qobjectWrapper)
1934 parent = qobjectWrapper->object();
1935 }
1936
1937 if (args->length() >= 2) {
1938 QV4::ScopedValue v(scope, (*args)[1]);
1939 if (v->isNull()) {
1940 } else if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
1941 qmlWarning(this) << tr("createObject: value is not an object");
1942 args->setReturnValue(QV4::Encode::null());
1943 return;
1944 } else {
1945 valuemap = v;
1946 }
1947 }
1948
1949 if (args->length() >= 3) {
1950 QV4::ScopedValue val(scope, (*args)[2]);
1951 quint32 v = val->toUInt32();
1952 if (v == 0)
1954 else if (v == 1)
1956 }
1957
1958 QQmlComponentExtension *e = componentExtension(args->v4engine());
1959
1962 r->setPrototypeOf(p);
1963
1964 if (!valuemap->isUndefined())
1965 r->d()->valuemapOrObject.set(scope.engine, valuemap);
1966 r->d()->qmlContext.set(scope.engine, v4->qmlContext());
1967 r->d()->parent = parent;
1968
1969 QQmlIncubator *incubator = r->d()->incubator;
1970 create(*incubator, creationContext());
1971
1972 if (incubator->status() == QQmlIncubator::Null) {
1973 args->setReturnValue(QV4::Encode::null());
1974 } else {
1975 args->setReturnValue(r.asReturnedValue());
1976 }
1977}
1978
1979// XXX used by QSGLoader
1981{
1982 QV4::ExecutionEngine *v4engine = engine->handle();
1983 QV4::Scope scope(v4engine);
1984
1985 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate));
1986 Q_ASSERT(object->as<QV4::Object>());
1987
1988 if (!valuemap.isUndefined()) {
1990 v4engine, qmlContext, object, valuemap, requiredProperties, toCreate, state.creator());
1991 }
1992}
1993
2006
2008{
2009 QV4::Scope scope(b);
2011 if (!o)
2013
2014 return QV4::QObjectWrapper::wrap(scope.engine, o->d()->incubator->object());
2015}
2016
2018{
2019 QV4::Scope scope(b);
2021 if (!o)
2023
2024 o->d()->incubator->forceCompletion();
2025
2027}
2028
2030{
2031 QV4::Scope scope(b);
2033 if (!o)
2035
2036 return QV4::Encode(o->d()->incubator->status());
2037}
2038
2040{
2041 QV4::Scope scope(b);
2043 if (!o)
2045
2046 return QV4::Encode(o->d()->statusChanged);
2047}
2048
2050{
2051 QV4::Scope scope(b);
2053 if (!o || argc < 1)
2055
2056 o->d()->statusChanged.set(scope.engine, argv[0]);
2057
2059}
2060
2064
2065void QV4::Heap::QmlIncubatorObject::init(QQmlIncubator::IncubationMode m)
2066{
2067 Object::init();
2068 valuemapOrObject.set(internalClass->engine, QV4::Value::undefinedValue());
2069 statusChanged.set(internalClass->engine, QV4::Value::undefinedValue());
2070 parent.init();
2071 qmlContext.set(internalClass->engine, nullptr);
2072 incubator = new QQmlComponentIncubator(this, m);
2073}
2074
2075void QV4::Heap::QmlIncubatorObject::destroy() {
2076 delete incubator;
2077 parent.destroy();
2078 Object::destroy();
2079}
2080
2082{
2083 QQmlComponent_setQmlParent(o, d()->parent);
2084
2085 if (!d()->valuemapOrObject.isUndefined()) {
2087 QV4::Scope scope(v4);
2089 QV4::Scoped<QV4::QmlContext> qmlCtxt(scope, d()->qmlContext);
2091 v4, qmlCtxt, obj, d()->valuemapOrObject, requiredProperties, o,
2092 QQmlIncubatorPrivate::get(d()->incubator)->creator.data());
2093 }
2094}
2095
2097{
2098 QV4::Scope scope(engine());
2099
2100 QObject *object = d()->incubator->object();
2101
2102 if (s == QQmlIncubator::Ready) {
2103 // We don't need the arguments anymore, but we still want to hold on to the object so
2104 // that it doesn't get gc'd
2105 d()->valuemapOrObject.set(scope.engine, QV4::QObjectWrapper::wrap(scope.engine, object));
2106
2107 QQmlData *ddata = QQmlData::get(object);
2108 Q_ASSERT(ddata);
2109 ddata->explicitIndestructibleSet = false;
2110 ddata->indestructible = false;
2111 }
2112
2114 if (f) {
2115 QV4::JSCallArguments jsCallData(scope, 1);
2116 *jsCallData.thisObject = this;
2117 jsCallData.args[0] = QV4::Value::fromUInt32(s);
2118 f->call(jsCallData);
2119 if (scope.hasException()) {
2122 }
2123 }
2124
2126 d()->incubator->incubatorObject.clear();
2127}
2128
2129#undef INITIALPROPERTIES_SOURCE
2130
2132
2133#include "moc_qqmlcomponent.cpp"
2134#include "moc_qqmlcomponentattached_p.cpp"
\inmodule QtCore
QString toString() const
Returns a deep copy of this string view's data as a QString.
Definition qstring.h:1218
\inmodule QtCore
Definition qbytearray.h:57
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
Definition qdir.h:184
const_iterator constFind(const Key &key) const noexcept
Definition qhash.h:1299
iterator erase(const_iterator it)
Definition qhash.h:1233
const_iterator cend() const noexcept
Definition qhash.h:1218
QV4::ExecutionEngine * handle() const
Definition qjsengine.h:298
QString arg(Args &&...args) const
void push_back(parameter_type t)
Definition qlist.h:675
qsizetype length() const noexcept
Definition qlist.h:399
reference emplaceBack(Args &&... args)
Definition qlist.h:882
void reserve(qsizetype size)
Definition qlist.h:753
bool isBindable() const
QObject * parent
Definition qobject.h:73
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2195
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
QQmlComponentAttached(QObject *parent=nullptr)
QV4::PersistentValue incubationProto
QQmlComponentExtension(QV4::ExecutionEngine *v4)
void setInitialState(QObject *o) override
Called after the object is first created, but before complex property bindings are evaluated and,...
void statusChanged(Status s) override
Called when the status of the incubator changes.
QQmlComponentIncubator(QV4::Heap::QmlIncubatorObject *inc, IncubationMode mode)
QV4::PersistentValue incubatorObject
static void complete(QQmlEnginePrivate *enginePriv, ConstructionState *state)
ConstructionState state
virtual void incubateObject(QQmlIncubator *incubationTask, QQmlComponent *component, QQmlEngine *engine, const QQmlRefPointer< QQmlContextData > &context, const QQmlRefPointer< QQmlContextData > &forContext)
QQmlRefPointer< QV4::ExecutableCompilationUnit > compilationUnit
QObject * beginCreate(QQmlRefPointer< QQmlContextData >)
std::vector< ConstructionState > DeferredState
static QQmlError unsetRequiredPropertyToQQmlError(const RequiredPropertyInfo &unsetRequiredProperty)
std::unique_ptr< QString > inlineComponentName
bool hadTopLevelRequiredProperties() const
bool setInitialProperty(QObject *component, const QString &name, const QVariant &value)
void typeDataProgress(QQmlTypeData *, qreal) override
void completeLoadFromModule(QAnyStringView uri, QAnyStringView typeName, QQmlType type, LoadHelper::ResolveTypeResult::Status moduleStatus, QQmlComponent::CompilationMode mode=QQmlComponent::PreferSynchronous)
QObject * doBeginCreate(QQmlComponent *q, QQmlContext *context)
static QQmlComponentPrivate * get(QQmlComponent *c)
QObject * createWithProperties(QObject *parent, const QVariantMap &properties, QQmlContext *context, CreateBehavior behavior=CreateDefault)
LoadHelper::ResolveTypeResult prepareLoadFromModule(QAnyStringView uri, QAnyStringView typeName)
void typeDataReady(QQmlTypeData *) override
static void completeDeferred(QQmlEnginePrivate *enginePriv, DeferredState *deferredState)
static void beginDeferred(QQmlEnginePrivate *enginePriv, QObject *object, DeferredState *deferredState)
void loadUrl(const QUrl &newUrl, QQmlComponent::CompilationMode mode=QQmlComponent::PreferSynchronous)
QQmlGuardedContextData creationContext
void fromTypeData(const QQmlRefPointer< QQmlTypeData > &data)
static void setInitialProperties(QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext, const QV4::Value &o, const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent, QQmlObjectCreator *creator)
\qmlmethod QtObject Component::createObject(QtObject parent, object properties)
void initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext, const QV4::Value &valuemap, QObject *toCreate, RequiredProperties *requiredProperties)
QQmlRefPointer< QQmlTypeData > typeData
static QQmlProperty removePropertyFromRequired(QObject *createdComponent, const QString &name, RequiredProperties *requiredProperties, QQmlEngine *engine, bool *wasInRequiredProperties=nullptr)
The QQmlComponent class encapsulates a QML component definition.
Status
\qmltype Component \instantiates QQmlComponent\inqmlmodule QtQml
bool isError() const
Returns true if status() == QQmlComponent::Error.
friend class QQmlObjectCreator
bool isBound() const
Returns true if the component was created in a QML files that specifies {pragma ComponentBehavior: Bo...
bool isNull() const
Returns true if status() == QQmlComponent::Null.
virtual QObject * beginCreate(QQmlContext *)
Create an object instance from this component, within the specified context.
bool isLoading() const
Returns true if status() == QQmlComponent::Loading.
static QQmlComponentAttached * qmlAttachedProperties(QObject *)
virtual void completeCreate()
This method provides advanced control over component instance creation.
void loadFromModule(QAnyStringView uri, QAnyStringView typeName, QQmlComponent::CompilationMode mode=PreferSynchronous)
Load the QQmlComponent for typeName in the module uri.
QQmlContext * creationContext() const
Returns the QQmlContext the component was created in.
void setInitialProperties(QObject *component, const QVariantMap &properties)
Set top-level properties of the component.
Status status
\qmlproperty enumeration Component::status
QList< QQmlError > errors() const
Returns the list of errors that occurred during the last compile or create operation.
Q_INVOKABLE QObject * createObject(QObject *parent=nullptr, const QVariantMap &properties={})
QUrl url
\qmlproperty url Component::url The component URL.
CompilationMode
Specifies whether the QQmlComponent should load the component immediately, or asynchonously.
qreal progress
\qmlproperty real Component::progress The progress of loading the component, from 0....
~QQmlComponent() override
Destruct the QQmlComponent.
bool isReady() const
Returns true if status() == QQmlComponent::Ready.
void setData(const QByteArray &, const QUrl &baseUrl)
Sets the QQmlComponent to use the given QML data.
void loadUrl(const QUrl &url)
Load the QQmlComponent from the provided url.
void progressChanged(qreal)
Emitted whenever the component's loading progress changes.
QQmlComponent(QObject *parent=nullptr)
Q_INVOKABLE void incubateObject(QQmlV4FunctionPtr)
\qmlmethod object Component::incubateObject(QtObject parent, object properties, enumeration mode)
QQmlEngine * engine() const
Returns the QQmlEngine of this component.
Q_INVOKABLE QString errorString() const
\qmlmethod string Component::errorString()
virtual QObject * create(QQmlContext *context=nullptr)
Create an object instance from this component, within the specified context.
QObject * createWithInitialProperties(const QVariantMap &initialProperties, QQmlContext *context=nullptr)
Create an object instance of this component, within the specified context, and initialize its top-lev...
void statusChanged(QQmlComponent::Status)
Emitted whenever the component's status changes.
static QQmlRefPointer< QQmlContextData > get(QQmlContext *context)
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
QQmlEngine * engine() const
Return the context's QQmlEngine, or \nullptr if the context has no QQmlEngine or the QQmlEngine was d...
static QQmlPropertyCache::ConstPtr ensurePropertyCache(QObject *object)
Definition qqmldata_p.h:252
quint32 explicitIndestructibleSet
Definition qqmldata_p.h:95
static QQmlData * get(QObjectPrivate *priv, bool create)
Definition qqmldata_p.h:199
quint32 indestructible
Definition qqmldata_p.h:92
Q_REQUIRED_RESULT QQmlError removeError()
void warning(const QQmlError &)
void incubate(QQmlIncubator &, const QQmlRefPointer< QQmlContextData > &)
static QQmlEnginePrivate * get(QQmlEngine *e)
void referenceScarceResources()
QQmlDelayedError * erroredBindings
void dereferenceScarceResources()
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
QQmlContext * rootContext() const
Returns the engine's root context.
QUrl baseUrl() const
Return the base URL for this engine.
QQmlEngine * qmlEngine(const QObject *object)
Returns the QQmlEngine associated with object, if any.
Definition qqml.cpp:80
The QQmlError class encapsulates a QML error.
Definition qqmlerror.h:18
QString description() const
Returns the error description.
int line() const
Returns the error line number.
QUrl url() const
Returns the url for the file that caused this error.
virtual void componentFinalized()=0
The customization point provided by this interface.
static QQmlIncubatorPrivate * get(QQmlIncubator *incubator)
The QQmlIncubator class allows QML objects to be created asynchronously.
void clear()
Clears the incubator.
IncubationMode
Specifies the mode the incubator operates in.
Status status() const
Return the current status of the incubator.
Status
Specifies the status of the QQmlIncubator.
static QString prettyTypeName(const QObject *object)
Returns the pretty QML type name (e.g.
static QList< QQmlPrivate::AutoParentFunction > parentFunctions()
bool finalize(QQmlInstantiationInterrupt &interrupt)
bool componentHadTopLevelRequiredProperties() const
QObject * create(int subComponentIndex=-1, QObject *parent=nullptr, QQmlInstantiationInterrupt *interrupt=nullptr, int flags=NormalObject)
The QQmlParserStatus class provides updates on the QML parser state.
virtual void classBegin()=0
Invoked after class creation, but before any properties have been set.
static void findAliasTarget(QObject *, QQmlPropertyIndex, QObject **, QQmlPropertyIndex *)
static QQmlPropertyPrivate * get(const QQmlProperty &p)
The QQmlProperty class abstracts accessing properties on objects created from QML.
bool isBindable() const
bool isValid() const
Returns true if the QQmlProperty refers to a valid property, otherwise false.
int index() const
Return the Qt metaobject index of the property.
QML_ANONYMOUSQObject * object
void reset(T *t=nullptr)
void registerCallback(TypeDataCallback *)
void unregisterCallback(TypeDataCallback *)
QObject * createWithQQmlData() const
Definition qqmltype.cpp:518
int finalizerCast() const
Definition qqmltype.cpp:744
bool isValid() const
Definition qqmltype_p.h:54
int parserStatusCast() const
Definition qqmltype.cpp:723
Exception-safe wrapper around QObject::blockSignals().
Definition qobject.h:483
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
QByteArray toUtf8() const &
Definition qstring.h:634
\inmodule QtCore
Definition qurl.h:94
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3368
bool isLocalFile() const
Definition qurl.cpp:3445
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition qurl.cpp:2725
void setFragment(const QString &fragment, ParsingMode mode=TolerantMode)
Sets the fragment of the URL to fragment.
Definition qurl.cpp:2648
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Definition qurl.cpp:2831
int inlineComponentId(const QString &inlineComponentName) const
ObjectType::Data * allocate(Args &&... args)
Definition qv4mm_p.h:298
ExecutionEngine * engine() const
ReturnedValue value() const
void set(ExecutionEngine *engine, const Value &value)
\inmodule QtCore
Definition qvariant.h:65
void statusChanged(QQmlComponent::Status status)
[1]
Definition qlogging.cpp:11
QSet< QString >::iterator it
else opt state
[0]
AutoParentResult(* AutoParentFunction)(QObject *object, QObject *parent)
Combined button and popup list for selecting options.
Scoped< FunctionObject > ScopedFunctionObject
quint64 ReturnedValue
Scoped< String > ScopedString
static void * context
static const QCssKnownValue properties[NumProperties - 1]
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qWarning
Definition qlogging.h:166
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
return ret
const char * typeName
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLenum mode
const GLfloat * m
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLboolean r
[2]
GLuint object
[3]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLenum type
GLenum target
GLbitfield flags
GLuint start
GLuint name
GLhandleARB obj
[2]
GLdouble s
[6]
Definition qopenglext.h:235
GLuint res
GLuint GLfloat * val
GLuint segment
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
static qreal component(const QPointF &point, unsigned int i)
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:80
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:75
static void removePendingQPropertyBinding(QV4::Value *object, const QString &propertyName, QQmlObjectCreator *creator)
static void QQmlComponent_setQmlParent(QObject *me, QObject *parent)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
Definition qscopeguard.h:60
SSL_CTX int void * arg
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
#define tr(X)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define emit
#define Q_UNUSED(x)
unsigned int quint32
Definition qtypes.h:50
double qreal
Definition qtypes.h:187
static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, qsizetype errorPosition)
Definition qurl.cpp:3517
static const uint base
Definition qurlidna.cpp:20
#define V4_DEFINE_EXTENSION(dataclass, datafunction)
Definition qv4engine_p.h:38
#define V4_NEEDS_DESTROY
#define DECLARE_HEAP_OBJECT(name, base)
#define DECLARE_MARKOBJECTS(class)
#define THROW_TYPE_ERROR()
#define RETURN_UNDEFINED()
#define DEFINE_OBJECT_VTABLE(classname)
#define V4_OBJECT2(DataClass, superClass)
QUrl url("example.com")
[constructor-url-reference]
QUrl baseUrl
QObject::connect nullptr
someQObject blockSignals(wasBlocked)
QItemEditorCreatorBase * creator
QFrame frame
[0]
QHostInfo info
[0]
view create()
QJSValueList args
QJSEngine engine
[0]
\inmodule QtCore \reentrant
Definition qchar.h:18
\inmodule QtCore
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
void appendErrors(const QList< QQmlError > &qmlErrors)
void addPendingRequiredProperty(const QObject *object, const QQmlPropertyData *propData, const RequiredPropertyInfo &info)
QQmlObjectCreator * initCreator(QQmlRefPointer< QQmlContextData > parentContext, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit, const QQmlRefPointer< QQmlContextData > &creationContext)
static constexpr ReturnedValue null()
MemoryManager * memoryManager
QQmlError catchExceptionAsQmlError()
Heap::Object * newObject()
Heap::String * newString(char16_t c)
QV4::ReturnedValue metaTypeToJS(QMetaType type, const void *data)
QQmlEngine * qmlEngine() const
static Heap::ExecutionContext * qmlContext(Heap::ExecutionContext *ctx)
QQmlRefPointer< ExecutableCompilationUnit > executableCompilationUnit(QQmlRefPointer< QV4::CompiledData::CompilationUnit > &&unit)
void defineDefaultProperty(StringOrSymbol *name, const Value &value, PropertyAttributes attributes=Attr_Data|Attr_NotEnumerable)
void defineAccessorProperty(const QString &name, VTable::Call getter, VTable::Call setter)
static ReturnedValue wrap(ExecutionEngine *engine, QObject *object)
static ReturnedValue method_set_statusChanged(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_status(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static V4_NEEDS_DESTROY ReturnedValue method_get_statusChanged(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_object(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void statusChanged(QQmlIncubator::Status)
void setInitialState(QObject *, RequiredProperties *requiredProperties)
static ReturnedValue method_forceCompletion(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
bool hasException() const
ExecutionEngine * engine
static constexpr Value undefinedValue()
Definition qv4value_p.h:191
const T * as() const
Definition qv4value_p.h:132
static Value fromUInt32(uint i)
Definition qv4value_p.h:203
void wrapper()