15#include <private/qqmljavascriptexpression_p.h>
16#include <private/qqmlsourcecoordinate_p.h>
18#include <private/qv4functionobject_p.h>
19#include <private/qv4script_p.h>
20#include <private/qv4scopedvalue_p.h>
21#include <private/qv4objectiterator_p.h>
22#include <private/qv4qobjectwrapper_p.h>
23#include <private/qv4jscall_p.h>
28#include <QThreadStorage>
29#include <QtCore/qdebug.h>
30#include <QtCore/qloggingcategory.h>
34using namespace Qt::Literals::StringLiterals;
37 Q_CONSTINIT
thread_local int creationDepth = 0;
44class QQmlComponentExtension :
public QV4::ExecutionEngine::Deletable
47 QQmlComponentExtension(QV4::ExecutionEngine *v4);
48 virtual ~QQmlComponentExtension();
50 QV4::PersistentValue incubationProto;
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
273
274
275
276
277
278
279
280
281
284
285
286
287
288
289
290
291
293void QQmlComponentPrivate::ready(QQmlNotifyingBlob *)
297 Q_ASSERT(m_typeData);
299 fromTypeData(m_typeData);
302 emit q->statusChanged(q->status());
305void QQmlComponentPrivate::progress(QQmlNotifyingBlob *, qreal p)
310void QQmlComponentPrivate::fromTypeData(
const QQmlRefPointer<QQmlTypeData> &data)
312 m_url = data->finalUrl();
313 if (
auto cu = data->compilationUnit())
314 m_compilationUnit = m_engine->handle()->executableCompilationUnit(std::move(cu));
316 if (!m_compilationUnit) {
317 Q_ASSERT(data->isError());
318 m_state.errors.clear();
319 m_state.appendErrors(data->errors());
323bool QQmlComponentPrivate::hadTopLevelRequiredProperties()
const
325 return m_state.creator()->componentHadTopLevelRequiredProperties();
328void QQmlComponentPrivate::clear()
331 m_typeData->unregisterCallback(
this);
336 m_loadHelper->unregisterCallback(
this);
337 m_loadHelper.reset();
340 m_compilationUnit.reset();
341 m_inlineComponentName.reset();
344QObject *QQmlComponentPrivate::doBeginCreate(QQmlComponent *q, QQmlContext *context)
348 qWarning(
"QQmlComponent: Must provide an engine before calling create");
352 context = m_engine->rootContext();
353 return q->beginCreate(context);
357 QV4::Value *object,
const QString &propertyName,
const QQmlObjectCreator *creator)
362 QV4::QObjectWrapper *wrapper = object->as<QV4::QObjectWrapper>();
366 QObject *o = wrapper->object();
370 if (QQmlData *ddata = QQmlData::get(o)) {
372 propertyName, o, ddata->outerContext);
373 if (propData && propData->acceptsQBinding())
374 creator->removePendingBinding(o, propData->coreIndex());
378 const QMetaObject *meta = o->metaObject();
380 const int index = meta->indexOfProperty(propertyName.toUtf8());
381 if (index != -1 && meta->property(index).isBindable())
382 creator->removePendingBinding(o, index);
385bool QQmlComponentPrivate::setInitialProperty(
386 QObject *base,
const QString &name,
const QVariant &value)
388 bool isComplexProperty = name.contains(u'.');
391 if (m_state.hasUnsetRequiredProperties() && !isComplexProperty)
392 prop = QQmlComponentPrivate::removePropertyFromRequired(
393 base, name, m_state.requiredProperties(), m_engine);
394 else if (QQmlContext *ctxt = qmlContext(base); ctxt)
395 prop = QQmlProperty(base, name, ctxt);
397 prop = QQmlProperty(base, name, m_engine);
399 if (!prop.isValid()) {
403 if (!isComplexProperty)
407 const QStringList properties = name.split(u'.');
408 QV4::Scope scope(m_engine->handle());
409 QV4::ScopedObject object(scope, QV4::QObjectWrapper::wrap(scope.engine, base));
410 QV4::ScopedString segment(scope);
411 for (
int i = 0; i < properties.size() - 1; ++i) {
412 segment = scope.engine->newString(properties.at(i));
413 object = object->get(segment);
414 if (scope.engine->hasException || object->isNullOrUndefined())
418 const QString lastProperty = properties.last();
419 if (!object->isNullOrUndefined()) {
420 segment = scope.engine->newString(lastProperty);
421 QV4::ScopedValue v(scope, scope.engine->metaTypeToJS(value.metaType(), value.constData()));
422 object->put(segment, v);
427 if (scope.engine->hasException) {
428 qmlWarning(base, scope.engine->catchExceptionAsQmlError());
429 scope.engine->hasException =
false;
433 removePendingQPropertyBinding(object, lastProperty, m_state.creator());
437 if (QQmlPropertyPrivate::get(prop)->writeValueProperty(value, {})) {
438 if (prop.isBindable()) {
439 if (QQmlObjectCreator *creator = m_state.creator())
440 creator->removePendingBinding(prop.object(), prop.index());
447 error.setDescription(QStringLiteral(
"Could not set initial property %1").arg(name));
448 qmlWarning(base, error);
453
454
455QQmlComponent::QQmlComponent(QObject *parent)
456 : QObject(*(
new QQmlComponentPrivate), parent)
461
462
463QQmlComponent::~QQmlComponent()
467 if (d->m_state.isCompletePending()) {
468 qWarning(
"QQmlComponent: Component destroyed while completion pending");
471 qWarning() <<
"This may have been caused by one of the following errors:";
472 for (
const QQmlComponentPrivate::AnnotatedQmlError &e : std::as_const(d->m_state.errors))
473 qWarning().nospace().noquote() << QLatin1String(
" ") << e.error;
477 if (d->m_state.hasCreator())
482 d->m_typeData->unregisterCallback(d);
483 if (d->m_engine && !d->m_typeData->isCompleteOrError()) {
486 QQmlTypeLoader::get(d->m_engine)->drop(QQmlDataBlob::Ptr(d->m_typeData.data()));
488 d->m_typeData.reset();
493
494
495
496
497
498
499
500
501
502
503
506
507
508
509QQmlComponent::Status QQmlComponent::status()
const
511 Q_D(
const QQmlComponent);
515 else if (!d->m_state.errors.isEmpty())
517 else if (d->m_engine && (d->m_compilationUnit || d->loadedType().isValid()))
519 else if (d->m_loadHelper)
526
527
528bool QQmlComponent::isNull()
const
530 return status() == Null;
534
535
536bool QQmlComponent::isReady()
const
538 return status() == Ready;
542
543
544bool QQmlComponent::isError()
const
546 return status() == Error;
550
551
552bool QQmlComponent::isLoading()
const
554 return status() == Loading;
558
559
560
561
562
563bool QQmlComponent::isBound()
const
565 Q_D(
const QQmlComponent);
570
571
572
573
576
577
578
579
580qreal QQmlComponent::progress()
const
582 Q_D(
const QQmlComponent);
583 return d->m_progress;
587
588
589
590
591
594
595
596
597
598
601
602
603
604QQmlComponent::QQmlComponent(QQmlEngine *engine, QObject *parent)
605 : QObject(*(
new QQmlComponentPrivate), parent)
608 d->m_engine = engine;
609 QObject::connect(engine, &QObject::destroyed,
this, [d]() {
611 d->m_engine =
nullptr;
616
617
618
619
620
621
622
623QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QUrl &url, QObject *parent)
624 : QQmlComponent(engine, url, QQmlComponent::PreferSynchronous, parent)
629
630
631
632
633
634
635
636
637QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QUrl &url, CompilationMode mode,
639 : QQmlComponent(engine, parent)
642 d->loadUrl(url, mode);
646
647
648
649
650
651
652
653
654QQmlComponent::QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, QObject *parent)
655 : QQmlComponent(engine, uri, typeName, QQmlComponent::PreferSynchronous, parent)
661
662
663
664
665
666
667
668
669QQmlComponent::QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, CompilationMode mode, QObject *parent)
670 : QQmlComponent(engine, parent)
672 loadFromModule(uri, typeName, mode);
676
677
678
679
680
681QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QString &fileName,
683 : QQmlComponent(engine, fileName, QQmlComponent::PreferSynchronous, parent)
688
689
690
691
692
693
694QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QString &fileName,
695 CompilationMode mode, QObject *parent)
696 : QQmlComponent(engine, parent)
699 if (fileName.startsWith(u':'))
700 d->loadUrl(QUrl(QLatin1String(
"qrc") + fileName), mode);
701 else if (QDir::isAbsolutePath(fileName))
702 d->loadUrl(QUrl::fromLocalFile(fileName), mode);
704 d->loadUrl(QUrl(fileName), mode);
708
709
710QQmlComponent::QQmlComponent(QQmlEngine *engine, QV4::ExecutableCompilationUnit *compilationUnit,
711 int start, QObject *parent)
712 : QQmlComponent(engine, parent)
715 d->m_compilationUnit.reset(compilationUnit);
717 d->m_url = compilationUnit->finalUrl();
722
723
724
725
726
727
728
729
730
731
732
733
734void QQmlComponent::setData(
const QByteArray &data,
const QUrl &url, CompilationMode compilationMode)
740 qWarning(
"QQmlComponent: Must provide an engine before calling setData");
751 d->m_engine->handle()->trimCompilationUnitsForUrl(url);
753 QQmlTypeLoader::Mode mode = compilationMode == Asynchronous
754 ? QQmlTypeLoader::Asynchronous
755 : QQmlTypeLoader::PreferSynchronous;
756 QQmlRefPointer<QQmlTypeData> typeData = QQmlTypeLoader::get(d->m_engine)->getType(data, url, mode);
758 if (typeData->isCompleteOrError()) {
759 d->fromTypeData(typeData);
762 d->m_typeData = typeData;
763 d->m_typeData->registerCallback(d);
764 d->setProgress(typeData->progress());
767 emit statusChanged(status());
771
772
773
774
775
776
777
778
779
780
781
782void QQmlComponent::setData(
const QByteArray &data,
const QUrl &url)
784 setData(data, url, PreferSynchronous);
788
789
790
791QQmlContext *QQmlComponent::creationContext()
const
793 Q_D(
const QQmlComponent);
794 if (!d->m_creationContext.isNull())
795 return d->m_creationContext->asQQmlContext();
797 return qmlContext(
this);
801
802
803
804
805QQmlEngine *QQmlComponent::engine()
const
807 Q_D(
const QQmlComponent);
812
813
814
815
816void QQmlComponent::loadUrl(
const QUrl &url)
823
824
825
826
827
828void QQmlComponent::loadUrl(
const QUrl &url, QQmlComponent::CompilationMode mode)
831 d->loadUrl(url, mode);
834void QQmlComponentPrivate::loadUrl(
const QUrl &newUrl, QQmlComponent::CompilationMode mode)
839 if (newUrl.isRelative()) {
841 m_url = m_engine->baseUrl().resolved(QUrl(newUrl.toString()));
842 }
else if (m_engine->baseUrl().isLocalFile() && newUrl.isLocalFile() && !QDir::isAbsolutePath(newUrl.toLocalFile())) {
846 QUrl fixedUrl(newUrl);
847 fixedUrl.setScheme(QString());
850 m_url = m_engine->baseUrl().resolved(fixedUrl);
855 if (m_url.scheme() ==
"qrc"_L1 && !m_url.path().startsWith(
"/"_L1)) {
856 qWarning().nospace().noquote()
857 <<
"QQmlComponent: attempted to load via a relative URL '" << m_url.toString()
858 <<
"' in resource file system. This is not fully supported and may not work";
861 if (newUrl.isEmpty()) {
863 error.setDescription(QQmlComponent::tr(
"Invalid empty URL"));
864 m_state.errors.emplaceBack(error);
870 QQmlTypeLoader::Mode loaderMode = (mode == QQmlComponent::Asynchronous)
871 ? QQmlTypeLoader::Asynchronous
872 : QQmlTypeLoader::PreferSynchronous;
873 QQmlRefPointer<QQmlTypeData> data = QQmlTypeLoader::get(m_engine)->getType(m_url, loaderMode);
875 if (data->isCompleteOrError()) {
880 m_typeData->registerCallback(
this);
881 setProgress(data->progress());
884 emit q->statusChanged(q->status());
888
889
890
891QList<QQmlError> QQmlComponent::errors()
const
893 Q_D(
const QQmlComponent);
894 QList<QQmlError> errors;
895 errors.reserve(d->m_state.errors.size());
896 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors)
897 errors.emplaceBack(annotated.error);
902
903
904
905
906
907
908
909
910
913
914
915
916QString QQmlComponent::errorString()
const
918 Q_D(
const QQmlComponent);
922 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors) {
923 ret += annotated.error.toString() + QLatin1Char(
'\n');
929
930
931
934
935
936
937
938QUrl QQmlComponent::url()
const
940 Q_D(
const QQmlComponent);
945
946
947QQmlComponent::QQmlComponent(QQmlComponentPrivate &dd, QObject *parent)
948 : QObject(dd, parent)
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968QObject *QQmlComponent::create(QQmlContext *context)
971 return d->createWithProperties(
972 nullptr, QVariantMap {}, context, QQmlComponentPrivate::CreateBehavior::Cpp);
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995QObject *QQmlComponent::createWithInitialProperties(
996 const QVariantMap& initialProperties, QQmlContext *context)
999 return d->createWithProperties(
1000 nullptr, initialProperties, context, QQmlComponentPrivate::CreateBehavior::Cpp);
1006
1007QObject *QQmlComponentPrivate::createWithProperties(
1008 QObject *parent,
const QVariantMap &properties,
1009 QQmlContext *context, CreateBehavior behavior)
1013 QObject *rv = doBeginCreate(q, context);
1015 if (m_state.isCompletePending()) {
1019 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
1020 complete(ep, &m_state);
1026 QQmlComponent_setQmlParent(rv, parent);
1028 if (behavior == CreateBehavior::Qml) {
1030 for (
auto it = properties.cbegin(), end = properties.cend(); it != end; ++it)
1031 ok = setInitialProperty(rv, it.key(), it.value()) && ok;
1032 q->completeCreate();
1033 if (m_state.hasUnsetRequiredProperties()) {
1034 for (
const auto &unsetRequiredProperty : std::as_const(*m_state.requiredProperties())) {
1035 const QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1036 qmlWarning(rv, error);
1038 delete std::exchange(rv,
nullptr);
1041 delete std::exchange(rv,
nullptr);
1044 setInitialProperties(rv, properties);
1045 q->completeCreate();
1046 if (m_state.hasUnsetRequiredProperties())
1047 delete std::exchange(rv,
nullptr);
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090QObject *QQmlComponent::beginCreate(QQmlContext *context)
1094 return d->beginCreate(QQmlContextData::get(context));
1099 const int parserStatusCast = type.parserStatusCast();
1100 return parserStatusCast == -1
1102 :
reinterpret_cast<QQmlParserStatus *>(
reinterpret_cast<
char *>(rv) + parserStatusCast);
1105QObject *QQmlComponentPrivate::beginCreate(QQmlRefPointer<QQmlContextData> context)
1108 auto cleanup = qScopeGuard([
this] {
1109 if (!m_state.errors.isEmpty() && lcQmlComponentGeneral().isDebugEnabled()) {
1110 for (
const auto &e : std::as_const(m_state.errors)) {
1111 qCDebug(lcQmlComponentGeneral) <<
"QQmlComponent: " << e.error.toString();
1116 qWarning(
"QQmlComponent: Cannot create a component in a null context");
1120 if (!context->isValid()) {
1121 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1125 if (context->engine() != m_engine) {
1126 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1130 if (m_state.isCompletePending()) {
1131 qWarning(
"QQmlComponent: Cannot create new component instance before completing the previous");
1137 m_state.errors.removeIf([](
const auto &e) {
return e.isTransient; });
1138 m_state.clearRequiredProperties();
1140 if (!q->isReady()) {
1141 qWarning(
"QQmlComponent: Component is not ready");
1146 static const int maxCreationDepth = 10;
1147 if (creationDepth >= maxCreationDepth) {
1148 qWarning(
"QQmlComponent: Component creation is recursing - aborting");
1152 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(m_engine);
1154 enginePriv->inProgressCreations++;
1155 m_state.errors.clear();
1156 m_state.setCompletePending(
true);
1158 QObject *rv =
nullptr;
1160 const QQmlType type = loadedType();
1161 if (!type.isValid()) {
1162 enginePriv->referenceScarceResources();
1163 const QString *icName = m_inlineComponentName.get();
1164 m_state.initCreator(
1165 context, m_compilationUnit, m_creationContext, icName ? *icName : QString());
1167 QQmlObjectCreator::CreationFlags flags;
1169 flags = QQmlObjectCreator::InlineComponent;
1171 m_start = m_compilationUnit->inlineComponentId(*icName);
1172 Q_ASSERT(m_start > 0);
1174 flags = QQmlObjectCreator::NormalObject;
1177 rv = m_state.creator()->create(m_start,
nullptr,
nullptr, flags);
1179 m_state.appendCreatorErrors();
1180 enginePriv->dereferenceScarceResources();
1183 rv = type.createWithQQmlData();
1184 QQmlPropertyCache::ConstPtr propertyCache = QQmlData::ensurePropertyCache(rv);
1185 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv)) {
1186 parserStatus->classBegin();
1187 m_state.ensureRequiredPropertyStorage(rv);
1188 }
else if (type.finalizerCast() != -1) {
1189 m_state.ensureRequiredPropertyStorage(rv);
1192 if (propertyCache) {
1193 for (
int i = 0, propertyCount = propertyCache->propertyCount(); i < propertyCount; ++i) {
1194 if (
const QQmlPropertyData *propertyData = propertyCache->property(i); propertyData->isRequired()) {
1195 m_state.ensureRequiredPropertyStorage(rv);
1196 RequiredPropertyInfo info;
1197 info.propertyName = propertyData->name(rv);
1198 m_state.addPendingRequiredProperty(rv, propertyData, info);
1209 QQmlData *ddata = QQmlData::get(rv);
1213 ddata->indestructible =
true;
1214 ddata->explicitIndestructibleSet =
true;
1215 ddata->rootObjectInCreation =
false;
1218 if (!ddata->outerContext)
1219 ddata->outerContext = context.data();
1220 if (!ddata->context)
1221 ddata->context = context.data();
1227void QQmlComponentPrivate::beginDeferred(QQmlEnginePrivate *enginePriv,
1228 QObject *object, DeferredState *deferredState)
1230 QQmlData *ddata = QQmlData::get(object);
1231 Q_ASSERT(!ddata->deferredData.isEmpty());
1233 deferredState->reserve(ddata->deferredData.size());
1235 for (QQmlData::DeferredData *deferredData : std::as_const(ddata->deferredData)) {
1236 enginePriv->inProgressCreations++;
1238 ConstructionState state;
1239 state.setCompletePending(
true);
1241 auto creator = state.initCreator(
1242 deferredData->context->parent(),
1243 deferredData->compilationUnit,
1244 QQmlRefPointer<QQmlContextData>(),
1245 deferredData->inlineComponentName
1248 if (!creator->populateDeferredProperties(object, deferredData))
1249 state.appendCreatorErrors();
1250 deferredData->bindings.clear();
1252 deferredState->push_back(std::move(state));
1256void QQmlComponentPrivate::completeDeferred(QQmlEnginePrivate *enginePriv, QQmlComponentPrivate::DeferredState *deferredState)
1258 for (ConstructionState &state : *deferredState)
1259 complete(enginePriv, &state);
1262void QQmlComponentPrivate::complete(QQmlEnginePrivate *enginePriv, ConstructionState *state)
1264 if (state->isCompletePending()) {
1265 QQmlInstantiationInterrupt interrupt;
1266 state->creator()->finalize(interrupt);
1268 state->setCompletePending(
false);
1270 enginePriv->inProgressCreations--;
1272 if (0 == enginePriv->inProgressCreations) {
1273 while (enginePriv->erroredBindings) {
1274 enginePriv->warning(enginePriv->erroredBindings->removeError());
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297QQmlProperty QQmlComponentPrivate::removePropertyFromRequired(
1298 QObject *target,
const QString &name, RequiredProperties *requiredProperties,
1299 QQmlEngine *engine,
bool *wasInRequiredProperties)
1301 Q_ASSERT(requiredProperties);
1303 const QQmlProperty prop(target, name, engine);
1304 if (!prop.isValid()) {
1305 if (wasInRequiredProperties)
1306 *wasInRequiredProperties =
false;
1310 const QQmlPropertyPrivate *privProp = QQmlPropertyPrivate::get(prop);
1314 const QQmlPropertyData *targetProp = &privProp->core;
1315 QQmlData *data = QQmlData::get(target);
1316 Q_ASSERT(data && data->propertyCache);
1318 if (targetProp->isAlias()) {
1319 if (requiredProperties->remove(
1320 { target, data->propertyCache->property(targetProp->coreIndex()) })) {
1324 QQmlPropertyIndex originalIndex(targetProp->coreIndex());
1325 QQmlPropertyIndex propIndex;
1326 QQmlPropertyPrivate::findAliasTarget(target, originalIndex, &target, &propIndex);
1327 data = QQmlData::get(target);
1328 Q_ASSERT(data && data->propertyCache);
1329 targetProp = data->propertyCache->property(propIndex.coreIndex());
1333 targetProp = data->propertyCache->property(targetProp->coreIndex());
1337 if (requiredProperties->remove({target, targetProp}))
1340 if (wasInRequiredProperties)
1341 *wasInRequiredProperties = found;
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356void QQmlComponent::completeCreate()
1360 d->completeCreate();
1363void QQmlComponentPrivate::completeCreate()
1365 if (m_state.hasUnsetRequiredProperties()) {
1366 for (
const auto& unsetRequiredProperty: std::as_const(*m_state.requiredProperties())) {
1367 QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1368 m_state.errors.push_back(QQmlComponentPrivate::AnnotatedQmlError { error,
true });
1372 const QQmlType type = loadedType();
1373 if (type.isValid()) {
1374 QObject *rv = m_state.target();
1375 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv))
1376 parserStatus->componentComplete();
1378 if (
const int finalizerCast = type.finalizerCast(); finalizerCast != -1) {
1379 auto *hook =
reinterpret_cast<QQmlFinalizerHook *>(
1380 reinterpret_cast<
char *>(rv) + finalizerCast);
1381 hook->componentFinalized();
1385
1386
1387
1388
1389 m_state.setCompletePending(
false);
1390 QQmlEnginePrivate::get(m_engine)->inProgressCreations--;
1391 }
else if (m_state.isCompletePending()) {
1393 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
1394 complete(ep, &m_state);
1399QQmlComponentAttached::QQmlComponentAttached(QObject *parent)
1400: QObject(parent), m_prev(
nullptr), m_next(
nullptr)
1404QQmlComponentAttached::~QQmlComponentAttached()
1406 if (m_prev) *m_prev = m_next;
1407 if (m_next) m_next->m_prev = m_prev;
1413
1414
1415QQmlComponentAttached *QQmlComponent::qmlAttachedProperties(QObject *obj)
1417 QQmlComponentAttached *a =
new QQmlComponentAttached(obj);
1419 QQmlEngine *engine = qmlEngine(obj);
1423 QQmlEnginePrivate *p = QQmlEnginePrivate::get(engine);
1424 if (p->activeObjectCreator) {
1425 a->insertIntoList(p->activeObjectCreator->componentAttachment());
1427 QQmlData *d = QQmlData::get(obj);
1429 Q_ASSERT(d->context);
1430 d->context->addComponentAttached(a);
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453void QQmlComponent::loadFromModule(QAnyStringView uri, QAnyStringView typeName,
1454 QQmlComponent::CompilationMode mode)
1458 QQmlTypeLoader::Mode typeLoaderMode = QQmlTypeLoader::Synchronous;
1460 case QQmlComponent::PreferSynchronous:
1461 typeLoaderMode = QQmlTypeLoader::PreferSynchronous;
1463 case QQmlComponent::Asynchronous:
1464 typeLoaderMode = QQmlTypeLoader::Asynchronous;
1468 d->prepareLoadFromModule(uri, typeName, typeLoaderMode);
1469 if (d->m_loadHelper->isCompleteOrError())
1470 d->completeLoadFromModule(uri, typeName);
1472 d->m_loadHelper->registerCallback(d);
1475void QQmlComponentPrivate::prepareLoadFromModule(
1476 QAnyStringView uri, QAnyStringView typeName, QQmlTypeLoader::Mode mode)
1480 m_loadHelper->unregisterCallback(
this);
1483 m_loadHelper = QQml::makeRefPointer<LoadHelper>(QQmlTypeLoader::get(m_engine), uri, typeName, mode);
1486void QQmlComponentPrivate::completeLoadFromModule(QAnyStringView uri, QAnyStringView typeName)
1491 auto reportError = [&](QString msg) {
1493 error.setDescription(msg);
1494 m_state.errors.push_back(std::move(error));
1496 emit q->statusChanged(q->Error);
1498 auto emitComplete = [&]() {
1500 emit q->statusChanged(q->status());
1505 const QQmlType type = m_loadHelper->type();
1507 if (m_loadHelper->resolveTypeResult() == LoadHelper::ResolveTypeResult::NoSuchModule) {
1508 reportError(QLatin1String(R"(No module named "%1" found)").arg(uri.toString()));
1509 }
else if (!type.isValid()) {
1510 reportError(QLatin1String(R"(Module "%1" contains no type named "%2")")
1511 .arg(uri.toString(), typeName.toString()));
1512 }
else if (type.isCreatable()) {
1514 }
else if (type.isComposite()) {
1515 QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous;
1516 switch (m_loadHelper->mode()) {
1517 case QQmlTypeLoader::Asynchronous:
1518 mode = QQmlComponent::Asynchronous;
1520 case QQmlTypeLoader::PreferSynchronous:
1521 case QQmlTypeLoader::Synchronous:
1522 mode = QQmlComponent::PreferSynchronous;
1527 loadUrl(type.sourceUrl(), mode);
1528 }
else if (type.isInlineComponentType()) {
1529 auto baseUrl = type.sourceUrl();
1530 baseUrl.setFragment(QString());
1532 Q_ASSERT(m_progress == 0.0);
1536 QSignalBlocker blockSignals(q);
1538 loadUrl(baseUrl, QQmlComponent::PreferSynchronous);
1541 if (m_progress != 0.0)
1542 emit q->progressChanged(m_progress);
1548 QString elementName = type.elementName();
1549 if (m_compilationUnit->inlineComponentId(elementName) == -1) {
1550 QString realTypeName = typeName.toString();
1551 realTypeName.truncate(realTypeName.indexOf(u'.'));
1552 QString errorMessage = R"(Type "%1" from module "%2" contains no inline component named "%3".)"_L1.arg(
1553 realTypeName, uri.toString(), elementName);
1554 if (elementName == u"qml")
1555 errorMessage +=
" To load the type \"%1\", drop the \".qml\" extension."_L1.arg(realTypeName);
1556 reportError(std::move(errorMessage));
1558 m_inlineComponentName = std::make_unique<QString>(std::move(elementName));
1561 }
else if (type.isSingleton() || type.isCompositeSingleton()) {
1562 reportError(QLatin1String(R"(%1 is a singleton, and cannot be loaded)").arg(typeName.toString()));
1564 reportError(QLatin1String(
"Could not load %1, as the type is uncreatable").arg(typeName.toString()));
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1588void QQmlComponent::create(QQmlIncubator &incubator, QQmlContext *context, QQmlContext *forContext)
1593 context = d->m_engine->rootContext();
1595 QQmlRefPointer<QQmlContextData> contextData = QQmlContextData::get(context);
1596 QQmlRefPointer<QQmlContextData> forContextData =
1597 forContext ? QQmlContextData::get(forContext) : contextData;
1599 if (!contextData->isValid()) {
1600 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1604 if (contextData->engine() != d->m_engine) {
1605 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1610 qWarning(
"QQmlComponent: Component is not ready");
1615 QExplicitlySharedDataPointer<QQmlIncubatorPrivate> p(incubator.d);
1617 if (d->loadedType().isValid()) {
1621 p->incubateCppBasedComponent(
this, context);
1625 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(d->m_engine);
1627 p->compilationUnit = d->m_compilationUnit;
1628 p->enginePriv = enginePriv;
1629 p->creator.reset(
new QQmlObjectCreator(
1630 contextData, d->m_compilationUnit, d->m_creationContext,
1631 d->m_inlineComponentName ? *d->m_inlineComponentName : QString(), p.data()));
1632 p->subComponentToCreate = d->m_start;
1634 enginePriv->incubate(incubator, forContextData);
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660void QQmlComponent::setInitialProperties(QObject *object,
const QVariantMap &properties)
1663 d->setInitialProperties(object, properties);
1666bool QQmlComponentPrivate::setInitialProperties(QObject *object,
const QVariantMap &properties)
1669 for (
auto it = properties.constBegin(); it != properties.constEnd(); ++it) {
1670 if (it.key().contains(u'.')) {
1671 auto segments = it.key().split(u'.');
1672 QString description = u"Setting initial properties failed: Cannot initialize nested "_s
1674 if (segments.size() >= 2) {
1675 QString s = u" To set %1.%2 as an initial property, create %1, set its "_s
1676 u"property %2, and pass %1 as an initial property."_s;
1677 description += s.arg(segments[0], segments[1]);
1680 error.setUrl(m_url);
1681 error.setDescription(description);
1682 qmlWarning(object, error);
1687 result = setInitialProperty(object, it.key(), it.value()) && result;
1693
1694
1695
1696
1697
1698
1699void QQmlComponentPrivate::incubateObject(
1700 QQmlIncubator *incubationTask,
1701 QQmlComponent *component,
1703 const QQmlRefPointer<QQmlContextData> &context,
1704 const QQmlRefPointer<QQmlContextData> &forContext)
1706 QQmlIncubatorPrivate *incubatorPriv = QQmlIncubatorPrivate::get(incubationTask);
1707 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(engine);
1708 QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component);
1710 incubatorPriv->compilationUnit = componentPriv->m_compilationUnit;
1711 incubatorPriv->enginePriv = enginePriv;
1712 incubatorPriv->creator.reset(
new QQmlObjectCreator(
1713 context, componentPriv->m_compilationUnit, componentPriv->m_creationContext,
1714 m_inlineComponentName ? *m_inlineComponentName : QString()));
1716 if (m_start == -1) {
1717 if (
const QString *icName = componentPriv->m_inlineComponentName.get()) {
1718 m_start = m_compilationUnit->inlineComponentId(*icName);
1719 Q_ASSERT(m_start > 0);
1722 incubatorPriv->subComponentToCreate = componentPriv->m_start;
1724 enginePriv->incubate(*incubationTask, forContext);
1735#define QmlIncubatorObjectMembers(class, Member)
1736 Member(class, HeapValue, HeapValue, valuemapOrObject)
1737 Member(class, HeapValue, HeapValue, statusChanged)
1738 Member(class, Pointer, QmlContext *, qmlContext)
1739 Member(class, NoMark, QQmlComponentIncubator *, incubator)
1740 Member(class, NoMark, QV4QPointer<QObject>, parent)
1743 DECLARE_MARKOBJECTS(QmlIncubatorObject)
1745 void init(QQmlIncubator::IncubationMode = QQmlIncubator::Asynchronous);
1746 inline void destroy();
1776 incubatorObject.set(inc->internalClass->engine, inc);
1780 QV4::Scope scope(incubatorObject.engine());
1781 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1782 i->statusChanged(s);
1786 QV4::Scope scope(incubatorObject.engine());
1787 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1788 auto d = QQmlIncubatorPrivate::get(
this);
1789 i->setInitialState(o, d->requiredProperties());
1799 me->setParent(parent);
1800 typedef QQmlPrivate::AutoParentFunction APF;
1801 QList<APF> functions = QQmlMetaType::parentFunctions();
1803 bool needParent =
false;
1804 for (
int ii = 0; ii < functions.size(); ++ii) {
1805 QQmlPrivate::AutoParentResult res = functions.at(ii)(me, parent);
1806 if (res == QQmlPrivate::Parented) {
1809 }
else if (res == QQmlPrivate::IncompatibleParent) {
1814 qmlWarning(me) <<
"Created graphical object was not placed in the graphics scene.";
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1861void QQmlComponentPrivate::setInitialProperties(
1862 QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext,
const QV4::Value &o,
1863 const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent,
1864 const QQmlObjectCreator *creator)
1866 QV4::Scope scope(engine);
1867 QV4::ScopedObject object(scope);
1868 QV4::ScopedObject valueMap(scope, v);
1869 QV4::ObjectIterator it(scope, valueMap, QV4::ObjectIterator::EnumerableOnly);
1870 QV4::ScopedString name(scope);
1871 QV4::ScopedValue val(scope);
1872 if (engine->hasException)
1876 QV4::ScopedStackFrame frame(scope, qmlContext ? qmlContext : engine->scriptContext());
1879 name = it.nextPropertyNameAsString(val);
1883 const QStringList properties = name->toQString().split(QLatin1Char(
'.'));
1884 bool isTopLevelProperty = properties.size() == 1;
1885 for (
int i = 0; i < properties.size() - 1; ++i) {
1886 name = engine->newString(properties.at(i));
1887 object = object->get(name);
1888 if (engine->hasException || !object) {
1892 if (engine->hasException) {
1893 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1898 error.setUrl(qmlContext ? qmlContext->qmlContext()->url() : QUrl());
1899 error.setDescription(QLatin1String(
"Cannot resolve property \"%1\".")
1900 .arg(properties.join(u'.')));
1901 qmlWarning(createdComponent, error);
1904 const QString lastProperty = properties.last();
1905 name = engine->newString(lastProperty);
1906 object->put(name, val);
1907 if (engine->hasException) {
1908 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1910 }
else if (isTopLevelProperty && requiredProperties) {
1911 auto prop = removePropertyFromRequired(createdComponent, name->toQString(),
1912 requiredProperties, engine->qmlEngine());
1915 removePendingQPropertyBinding(object, lastProperty, creator);
1918 engine->hasException =
false;
1921QQmlError QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(
const RequiredPropertyInfo &unsetRequiredProperty)
1924 QString description = QLatin1String(
"Required property %1 was not initialized").arg(unsetRequiredProperty.propertyName);
1925 switch (unsetRequiredProperty.aliasesToRequired.size()) {
1929 const auto info = unsetRequiredProperty.aliasesToRequired.first();
1930 description += QLatin1String(
"\nIt can be set via the alias property %1 from %2\n").arg(info.propertyName, info.fileUrl.toString());
1934 description += QLatin1String(
"\nIt can be set via one of the following alias properties:");
1935 for (
const auto &aliasInfo: unsetRequiredProperty.aliasesToRequired) {
1936 description += QLatin1String(
"\n- %1 (%2)").arg(aliasInfo.propertyName, aliasInfo.fileUrl.toString());
1938 description += QLatin1Char(
'\n');
1940 error.setDescription(description);
1941 error.setUrl(unsetRequiredProperty.fileUrl);
1942 error.setLine(qmlConvertSourceCoordinate<quint32,
int>(
1943 unsetRequiredProperty.location.line()));
1944 error.setColumn(qmlConvertSourceCoordinate<quint32,
int>(
1945 unsetRequiredProperty.location.column()));
1949#if QT_DEPRECATED_SINCE(6
, 3
)
1951
1952
1953void QQmlComponent::createObject(QQmlV4FunctionPtr args)
1956 Q_ASSERT(d->m_engine);
1959 qmlWarning(
this) <<
"Unsuitable arguments passed to createObject(). The first argument should "
1960 "be a QObject* or null, and the second argument should be a JavaScript "
1961 "object or a QVariantMap";
1963 QObject *parent =
nullptr;
1964 QV4::ExecutionEngine *v4 = args->v4engine();
1965 QV4::Scope scope(v4);
1966 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
1968 if (args->length() >= 1) {
1969 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
1971 parent = qobjectWrapper->object();
1974 if (args->length() >= 2) {
1975 QV4::ScopedValue v(scope, (*args)[1]);
1976 if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
1977 qmlWarning(
this) << tr(
"createObject: value is not an object");
1978 args->setReturnValue(QV4::Encode::null());
1984 QQmlContext *ctxt = creationContext();
1985 if (!ctxt) ctxt = d->m_engine->rootContext();
1987 QObject *rv = beginCreate(ctxt);
1990 args->setReturnValue(QV4::Encode::null());
1994 QQmlComponent_setQmlParent(rv, parent);
1996 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4, rv));
1997 Q_ASSERT(object->isObject());
1999 if (!valuemap->isUndefined()) {
2000 QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->qmlContext());
2001 QQmlComponentPrivate::setInitialProperties(
2002 v4, qmlContext, object, valuemap, d->m_state.requiredProperties(), rv,
2003 d->m_state.creator());
2005 if (d->m_state.hasUnsetRequiredProperties()) {
2006 QList<QQmlError> errors;
2007 for (
const auto &requiredProperty: std::as_const(*d->m_state.requiredProperties())) {
2008 errors.push_back(QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(requiredProperty));
2010 qmlWarning(rv, errors);
2011 args->setReturnValue(QV4::Encode::null());
2016 d->completeCreate();
2018 Q_ASSERT(QQmlData::get(rv));
2019 QQmlData::get(rv)->explicitIndestructibleSet =
false;
2020 QQmlData::get(rv)->indestructible =
false;
2022 args->setReturnValue(object->asReturnedValue());
2027
2028
2029QObject *QQmlComponent::createObject(QObject *parent,
const QVariantMap &properties)
2032 Q_ASSERT(d->m_engine);
2033 QObject *rv = d->createWithProperties(
2034 parent, properties, creationContext(), QQmlComponentPrivate::CreateBehavior::Qml);
2036 QQmlData *qmlData = QQmlData::get(rv);
2038 qmlData->explicitIndestructibleSet =
false;
2039 qmlData->indestructible =
false;
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2100
2101
2102void QQmlComponent::incubateObject(QQmlV4FunctionPtr args)
2105 Q_ASSERT(d->m_engine);
2108 QV4::ExecutionEngine *v4 = args->v4engine();
2109 QV4::Scope scope(v4);
2111 QObject *parent =
nullptr;
2112 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
2113 QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous;
2115 if (args->length() >= 1) {
2116 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
2118 parent = qobjectWrapper->object();
2121 if (args->length() >= 2) {
2122 QV4::ScopedValue v(scope, (*args)[1]);
2124 }
else if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
2125 qmlWarning(
this) << tr(
"createObject: value is not an object");
2126 args->setReturnValue(QV4::Encode::null());
2133 if (args->length() >= 3) {
2134 QV4::ScopedValue val(scope, (*args)[2]);
2135 quint32 v = val->toUInt32();
2137 mode = QQmlIncubator::Asynchronous;
2139 mode = QQmlIncubator::AsynchronousIfNested;
2142 QQmlComponentExtension *e = componentExtension(args->v4engine());
2144 QV4::Scoped<QV4::QmlIncubatorObject> r(scope, v4->memoryManager->allocate<QV4::QmlIncubatorObject>(mode));
2145 QV4::ScopedObject p(scope, e->incubationProto.value());
2146 r->setPrototypeOf(p);
2148 if (!valuemap->isUndefined())
2149 r->d()->valuemapOrObject.set(scope.engine, valuemap);
2150 r->d()->qmlContext.set(scope.engine, v4->qmlContext());
2151 r->d()->parent = parent;
2153 QQmlIncubator *incubator = r->d()->incubator;
2154 create(*incubator, creationContext());
2156 if (incubator->status() == QQmlIncubator::Null) {
2157 args->setReturnValue(QV4::Encode::null());
2159 args->setReturnValue(r.asReturnedValue());
2164void QQmlComponentPrivate::initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext,
const QV4::Value &valuemap, QObject *toCreate, RequiredProperties *requiredProperties)
2166 QV4::ExecutionEngine *v4engine = m_engine->handle();
2167 QV4::Scope scope(v4engine);
2169 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate));
2170 Q_ASSERT(object->as<QV4::Object>());
2172 if (!valuemap.isUndefined()) {
2173 setInitialProperties(
2174 v4engine, qmlContext, object, valuemap, requiredProperties, toCreate, m_state.creator());
2178QQmlComponentExtension::QQmlComponentExtension(QV4::ExecutionEngine *v4)
2180 QV4::Scope scope(v4);
2181 QV4::ScopedObject proto(scope, v4->newObject());
2182 proto->defineAccessorProperty(QStringLiteral(
"onStatusChanged"),
2183 QV4::QmlIncubatorObject::method_get_statusChanged, QV4::QmlIncubatorObject::method_set_statusChanged);
2184 proto->defineAccessorProperty(QStringLiteral(
"status"), QV4::QmlIncubatorObject::method_get_status,
nullptr);
2185 proto->defineAccessorProperty(QStringLiteral(
"object"), QV4::QmlIncubatorObject::method_get_object,
nullptr);
2186 proto->defineDefaultProperty(QStringLiteral(
"forceCompletion"), QV4::QmlIncubatorObject::method_forceCompletion);
2188 incubationProto.set(v4, proto);
2191QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_object(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2193 QV4::Scope scope(b);
2194 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2198 return QV4::QObjectWrapper::wrap(scope.engine, o->d()->incubator->object());
2201QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_forceCompletion(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2203 QV4::Scope scope(b);
2204 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2208 o->d()->incubator->forceCompletion();
2213QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_status(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2215 QV4::Scope scope(b);
2216 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2220 return QV4::Encode(o->d()->incubator->status());
2223QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2225 QV4::Scope scope(b);
2226 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2230 return QV4::Encode(o->d()->statusChanged);
2233QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_set_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *argv,
int argc)
2235 QV4::Scope scope(b);
2236 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2240 o->d()->statusChanged.set(scope.engine, argv[0]);
2245QQmlComponentExtension::~QQmlComponentExtension()
2249void QV4::Heap::QmlIncubatorObject::init(QQmlIncubator::IncubationMode m)
2252 valuemapOrObject.set(internalClass->engine, QV4::Value::undefinedValue());
2253 statusChanged.set(internalClass->engine, QV4::Value::undefinedValue());
2255 qmlContext.set(internalClass->engine,
nullptr);
2256 incubator =
new QQmlComponentIncubator(
this, m);
2259void QV4::Heap::QmlIncubatorObject::destroy() {
2267 QQmlComponent_setQmlParent(o, d()->parent);
2269 if (!d()->valuemapOrObject.isUndefined()) {
2270 QV4::ExecutionEngine *v4 = engine();
2271 QV4::Scope scope(v4);
2272 QV4::ScopedObject obj(scope, QV4::QObjectWrapper::wrap(v4, o));
2273 QV4::Scoped<QV4::QmlContext> qmlCtxt(scope, d()->qmlContext);
2274 QQmlComponentPrivate::setInitialProperties(
2275 v4, qmlCtxt, obj, d()->valuemapOrObject, requiredProperties, o,
2276 QQmlIncubatorPrivate::get(d()->incubator)->creator.data());
2282 QV4::Scope scope(engine());
2284 QObject *object = d()->incubator->object();
2286 if (s == QQmlIncubator::Ready) {
2289 d()->valuemapOrObject.set(scope.engine, QV4::QObjectWrapper::wrap(scope.engine, object));
2291 QQmlData *ddata = QQmlData::get(object);
2293 ddata->explicitIndestructibleSet =
false;
2294 ddata->indestructible =
false;
2297 QV4::ScopedFunctionObject f(scope, d()->statusChanged);
2299 QV4::JSCallArguments jsCallData(scope, 1);
2300 *jsCallData.thisObject =
this;
2301 jsCallData.args[0] = QV4::Value::fromUInt32(s);
2302 f->call(jsCallData);
2303 if (scope.hasException()) {
2304 QQmlError error = scope.engine->catchExceptionAsQmlError();
2305 QQmlEnginePrivate::warning(QQmlEnginePrivate::get(scope.engine->qmlEngine()), error);
2309 if (s != QQmlIncubator::Loading)
2310 d()->incubator->incubatorObject.clear();
2313#undef INITIALPROPERTIES_SOURCE
2317#include "moc_qqmlcomponent.cpp"
2318#include "moc_qqmlcomponentattached_p.cpp"
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
The QQmlError class encapsulates a QML error.
Status
Specifies the status of the QQmlIncubator.
DECLARE_HEAP_OBJECT(QmlContext, ExecutionContext)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
static void removePendingQPropertyBinding(QV4::Value *object, const QString &propertyName, const QQmlObjectCreator *creator)
static void QQmlComponent_setQmlParent(QObject *me, QObject *parent)
DEFINE_OBJECT_VTABLE(QV4::QmlIncubatorObject)
V4_DEFINE_EXTENSION(QQmlComponentExtension, componentExtension)
static QQmlParserStatus * parserStatusCast(const QQmlType &type, QObject *rv)
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 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)