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");
748 QQmlTypeLoader::Mode mode = compilationMode == Asynchronous
749 ? QQmlTypeLoader::Asynchronous
750 : QQmlTypeLoader::PreferSynchronous;
751 QQmlRefPointer<QQmlTypeData> typeData = QQmlTypeLoader::get(d->m_engine)->getType(data, url, mode);
753 if (typeData->isCompleteOrError()) {
754 d->fromTypeData(typeData);
757 d->m_typeData = typeData;
758 d->m_typeData->registerCallback(d);
759 d->setProgress(typeData->progress());
762 emit statusChanged(status());
766
767
768
769
770
771
772
773
774
775
776
777void QQmlComponent::setData(
const QByteArray &data,
const QUrl &url)
779 setData(data, url, PreferSynchronous);
783
784
785
786QQmlContext *QQmlComponent::creationContext()
const
788 Q_D(
const QQmlComponent);
789 if (!d->m_creationContext.isNull())
790 return d->m_creationContext->asQQmlContext();
792 return qmlContext(
this);
796
797
798
799
800QQmlEngine *QQmlComponent::engine()
const
802 Q_D(
const QQmlComponent);
807
808
809
810
811void QQmlComponent::loadUrl(
const QUrl &url)
818
819
820
821
822
823void QQmlComponent::loadUrl(
const QUrl &url, QQmlComponent::CompilationMode mode)
826 d->loadUrl(url, mode);
829void QQmlComponentPrivate::loadUrl(
const QUrl &newUrl, QQmlComponent::CompilationMode mode)
834 if (newUrl.isRelative()) {
836 m_url = m_engine->baseUrl().resolved(QUrl(newUrl.toString()));
837 }
else if (m_engine->baseUrl().isLocalFile() && newUrl.isLocalFile() && !QDir::isAbsolutePath(newUrl.toLocalFile())) {
841 QUrl fixedUrl(newUrl);
842 fixedUrl.setScheme(QString());
845 m_url = m_engine->baseUrl().resolved(fixedUrl);
850 if (m_url.scheme() ==
"qrc"_L1 && !m_url.path().startsWith(
"/"_L1)) {
851 qWarning().nospace().noquote()
852 <<
"QQmlComponent: attempted to load via a relative URL '" << m_url.toString()
853 <<
"' in resource file system. This is not fully supported and may not work";
856 if (newUrl.isEmpty()) {
858 error.setDescription(QQmlComponent::tr(
"Invalid empty URL"));
859 m_state.errors.emplaceBack(error);
865 QQmlTypeLoader::Mode loaderMode = (mode == QQmlComponent::Asynchronous)
866 ? QQmlTypeLoader::Asynchronous
867 : QQmlTypeLoader::PreferSynchronous;
868 QQmlRefPointer<QQmlTypeData> data = QQmlTypeLoader::get(m_engine)->getType(m_url, loaderMode);
870 if (data->isCompleteOrError()) {
875 m_typeData->registerCallback(
this);
876 setProgress(data->progress());
879 emit q->statusChanged(q->status());
883
884
885
886QList<QQmlError> QQmlComponent::errors()
const
888 Q_D(
const QQmlComponent);
889 QList<QQmlError> errors;
890 errors.reserve(d->m_state.errors.size());
891 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors)
892 errors.emplaceBack(annotated.error);
897
898
899
900
901
902
903
904
905
908
909
910
911QString QQmlComponent::errorString()
const
913 Q_D(
const QQmlComponent);
917 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors) {
918 ret += annotated.error.toString() + QLatin1Char(
'\n');
924
925
926
929
930
931
932
933QUrl QQmlComponent::url()
const
935 Q_D(
const QQmlComponent);
940
941
942QQmlComponent::QQmlComponent(QQmlComponentPrivate &dd, QObject *parent)
943 : QObject(dd, parent)
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963QObject *QQmlComponent::create(QQmlContext *context)
966 return d->createWithProperties(
967 nullptr, QVariantMap {}, context, QQmlComponentPrivate::CreateBehavior::Cpp);
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990QObject *QQmlComponent::createWithInitialProperties(
991 const QVariantMap& initialProperties, QQmlContext *context)
994 return d->createWithProperties(
995 nullptr, initialProperties, context, QQmlComponentPrivate::CreateBehavior::Cpp);
1001
1002QObject *QQmlComponentPrivate::createWithProperties(
1003 QObject *parent,
const QVariantMap &properties,
1004 QQmlContext *context, CreateBehavior behavior)
1008 QObject *rv = doBeginCreate(q, context);
1010 if (m_state.isCompletePending()) {
1014 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
1015 complete(ep, &m_state);
1021 QQmlComponent_setQmlParent(rv, parent);
1023 if (behavior == CreateBehavior::Qml) {
1025 for (
auto it = properties.cbegin(), end = properties.cend(); it != end; ++it)
1026 ok = setInitialProperty(rv, it.key(), it.value()) && ok;
1027 q->completeCreate();
1028 if (m_state.hasUnsetRequiredProperties()) {
1029 for (
const auto &unsetRequiredProperty : std::as_const(*m_state.requiredProperties())) {
1030 const QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1031 qmlWarning(rv, error);
1033 delete std::exchange(rv,
nullptr);
1036 delete std::exchange(rv,
nullptr);
1039 setInitialProperties(rv, properties);
1040 q->completeCreate();
1041 if (m_state.hasUnsetRequiredProperties())
1042 delete std::exchange(rv,
nullptr);
1049
1050
1051
1052
1053
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
1085QObject *QQmlComponent::beginCreate(QQmlContext *context)
1089 return d->beginCreate(QQmlContextData::get(context));
1094 const int parserStatusCast = type.parserStatusCast();
1095 return parserStatusCast == -1
1097 :
reinterpret_cast<QQmlParserStatus *>(
reinterpret_cast<
char *>(rv) + parserStatusCast);
1100QObject *QQmlComponentPrivate::beginCreate(QQmlRefPointer<QQmlContextData> context)
1103 auto cleanup = qScopeGuard([
this] {
1104 if (!m_state.errors.isEmpty() && lcQmlComponentGeneral().isDebugEnabled()) {
1105 for (
const auto &e : std::as_const(m_state.errors)) {
1106 qCDebug(lcQmlComponentGeneral) <<
"QQmlComponent: " << e.error.toString();
1111 qWarning(
"QQmlComponent: Cannot create a component in a null context");
1115 if (!context->isValid()) {
1116 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1120 if (context->engine() != m_engine) {
1121 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1125 if (m_state.isCompletePending()) {
1126 qWarning(
"QQmlComponent: Cannot create new component instance before completing the previous");
1132 m_state.errors.removeIf([](
const auto &e) {
return e.isTransient; });
1133 m_state.clearRequiredProperties();
1135 if (!q->isReady()) {
1136 qWarning(
"QQmlComponent: Component is not ready");
1141 static const int maxCreationDepth = 10;
1142 if (creationDepth >= maxCreationDepth) {
1143 qWarning(
"QQmlComponent: Component creation is recursing - aborting");
1147 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(m_engine);
1149 enginePriv->inProgressCreations++;
1150 m_state.errors.clear();
1151 m_state.setCompletePending(
true);
1153 QObject *rv =
nullptr;
1155 const QQmlType type = loadedType();
1156 if (!type.isValid()) {
1157 enginePriv->referenceScarceResources();
1158 const QString *icName = m_inlineComponentName.get();
1159 m_state.initCreator(
1160 context, m_compilationUnit, m_creationContext, icName ? *icName : QString());
1162 QQmlObjectCreator::CreationFlags flags;
1164 flags = QQmlObjectCreator::InlineComponent;
1166 m_start = m_compilationUnit->inlineComponentId(*icName);
1167 Q_ASSERT(m_start > 0);
1169 flags = QQmlObjectCreator::NormalObject;
1172 rv = m_state.creator()->create(m_start,
nullptr,
nullptr, flags);
1174 m_state.appendCreatorErrors();
1175 enginePriv->dereferenceScarceResources();
1178 rv = type.createWithQQmlData();
1179 QQmlPropertyCache::ConstPtr propertyCache = QQmlData::ensurePropertyCache(rv);
1180 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv)) {
1181 parserStatus->classBegin();
1182 m_state.ensureRequiredPropertyStorage(rv);
1183 }
else if (type.finalizerCast() != -1) {
1184 m_state.ensureRequiredPropertyStorage(rv);
1187 if (propertyCache) {
1188 for (
int i = 0, propertyCount = propertyCache->propertyCount(); i < propertyCount; ++i) {
1189 if (
const QQmlPropertyData *propertyData = propertyCache->property(i); propertyData->isRequired()) {
1190 m_state.ensureRequiredPropertyStorage(rv);
1191 RequiredPropertyInfo info;
1192 info.propertyName = propertyData->name(rv);
1193 m_state.addPendingRequiredProperty(rv, propertyData, info);
1204 QQmlData *ddata = QQmlData::get(rv);
1208 ddata->indestructible =
true;
1209 ddata->explicitIndestructibleSet =
true;
1210 ddata->rootObjectInCreation =
false;
1213 if (!ddata->outerContext)
1214 ddata->outerContext = context.data();
1215 if (!ddata->context)
1216 ddata->context = context.data();
1222void QQmlComponentPrivate::beginDeferred(QQmlEnginePrivate *enginePriv,
1223 QObject *object, DeferredState *deferredState)
1225 QQmlData *ddata = QQmlData::get(object);
1226 Q_ASSERT(!ddata->deferredData.isEmpty());
1228 deferredState->reserve(ddata->deferredData.size());
1230 for (QQmlData::DeferredData *deferredData : std::as_const(ddata->deferredData)) {
1231 enginePriv->inProgressCreations++;
1233 ConstructionState state;
1234 state.setCompletePending(
true);
1236 auto creator = state.initCreator(
1237 deferredData->context->parent(),
1238 deferredData->compilationUnit,
1239 QQmlRefPointer<QQmlContextData>(),
1240 deferredData->inlineComponentName
1243 if (!creator->populateDeferredProperties(object, deferredData))
1244 state.appendCreatorErrors();
1245 deferredData->bindings.clear();
1247 deferredState->push_back(std::move(state));
1251void QQmlComponentPrivate::completeDeferred(QQmlEnginePrivate *enginePriv, QQmlComponentPrivate::DeferredState *deferredState)
1253 for (ConstructionState &state : *deferredState)
1254 complete(enginePriv, &state);
1257void QQmlComponentPrivate::complete(QQmlEnginePrivate *enginePriv, ConstructionState *state)
1259 if (state->isCompletePending()) {
1260 QQmlInstantiationInterrupt interrupt;
1261 state->creator()->finalize(interrupt);
1263 state->setCompletePending(
false);
1265 enginePriv->inProgressCreations--;
1267 if (0 == enginePriv->inProgressCreations) {
1268 while (enginePriv->erroredBindings) {
1269 enginePriv->warning(enginePriv->erroredBindings->removeError());
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292QQmlProperty QQmlComponentPrivate::removePropertyFromRequired(
1293 QObject *createdComponent,
const QString &name,
1294 RequiredProperties *requiredProperties, QQmlEngine *engine,
1295 bool *wasInRequiredProperties)
1297 Q_ASSERT(requiredProperties);
1298 QQmlProperty prop(createdComponent, name, engine);
1299 auto privProp = QQmlPropertyPrivate::get(prop);
1300 if (prop.isValid()) {
1302 const QQmlPropertyData *targetProp = &privProp->core;
1303 if (targetProp->isAlias()) {
1304 auto target = createdComponent;
1305 QQmlPropertyIndex originalIndex(targetProp->coreIndex());
1306 QQmlPropertyIndex propIndex;
1307 QQmlPropertyPrivate::findAliasTarget(target, originalIndex, &target, &propIndex);
1308 QQmlData *data = QQmlData::get(target);
1309 Q_ASSERT(data && data->propertyCache);
1310 targetProp = data->propertyCache->property(propIndex.coreIndex());
1314 QQmlData *data = QQmlData::get(createdComponent);
1315 Q_ASSERT(data && data->propertyCache);
1316 targetProp = data->propertyCache->property(targetProp->coreIndex());
1318 auto it = requiredProperties->constFind({createdComponent, targetProp});
1319 if (it != requiredProperties->cend()) {
1320 if (wasInRequiredProperties)
1321 *wasInRequiredProperties =
true;
1322 requiredProperties->erase(it);
1324 if (wasInRequiredProperties)
1325 *wasInRequiredProperties =
false;
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341void QQmlComponent::completeCreate()
1345 d->completeCreate();
1348void QQmlComponentPrivate::completeCreate()
1350 if (m_state.hasUnsetRequiredProperties()) {
1351 for (
const auto& unsetRequiredProperty: std::as_const(*m_state.requiredProperties())) {
1352 QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1353 m_state.errors.push_back(QQmlComponentPrivate::AnnotatedQmlError { error,
true });
1357 const QQmlType type = loadedType();
1358 if (type.isValid()) {
1359 QObject *rv = m_state.target();
1360 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv))
1361 parserStatus->componentComplete();
1363 if (
const int finalizerCast = type.finalizerCast(); finalizerCast != -1) {
1364 auto *hook =
reinterpret_cast<QQmlFinalizerHook *>(
1365 reinterpret_cast<
char *>(rv) + finalizerCast);
1366 hook->componentFinalized();
1370
1371
1372
1373
1374 m_state.setCompletePending(
false);
1375 QQmlEnginePrivate::get(m_engine)->inProgressCreations--;
1376 }
else if (m_state.isCompletePending()) {
1378 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
1379 complete(ep, &m_state);
1384QQmlComponentAttached::QQmlComponentAttached(QObject *parent)
1385: QObject(parent), m_prev(
nullptr), m_next(
nullptr)
1389QQmlComponentAttached::~QQmlComponentAttached()
1391 if (m_prev) *m_prev = m_next;
1392 if (m_next) m_next->m_prev = m_prev;
1398
1399
1400QQmlComponentAttached *QQmlComponent::qmlAttachedProperties(QObject *obj)
1402 QQmlComponentAttached *a =
new QQmlComponentAttached(obj);
1404 QQmlEngine *engine = qmlEngine(obj);
1408 QQmlEnginePrivate *p = QQmlEnginePrivate::get(engine);
1409 if (p->activeObjectCreator) {
1410 a->insertIntoList(p->activeObjectCreator->componentAttachment());
1412 QQmlData *d = QQmlData::get(obj);
1414 Q_ASSERT(d->context);
1415 d->context->addComponentAttached(a);
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438void QQmlComponent::loadFromModule(QAnyStringView uri, QAnyStringView typeName,
1439 QQmlComponent::CompilationMode mode)
1443 QQmlTypeLoader::Mode typeLoaderMode = QQmlTypeLoader::Synchronous;
1445 case QQmlComponent::PreferSynchronous:
1446 typeLoaderMode = QQmlTypeLoader::PreferSynchronous;
1448 case QQmlComponent::Asynchronous:
1449 typeLoaderMode = QQmlTypeLoader::Asynchronous;
1453 d->prepareLoadFromModule(uri, typeName, typeLoaderMode);
1454 if (d->m_loadHelper->isCompleteOrError())
1455 d->completeLoadFromModule(uri, typeName);
1457 d->m_loadHelper->registerCallback(d);
1460void QQmlComponentPrivate::prepareLoadFromModule(
1461 QAnyStringView uri, QAnyStringView typeName, QQmlTypeLoader::Mode mode)
1465 m_loadHelper->unregisterCallback(
this);
1468 m_loadHelper = QQml::makeRefPointer<LoadHelper>(QQmlTypeLoader::get(m_engine), uri, typeName, mode);
1471void QQmlComponentPrivate::completeLoadFromModule(QAnyStringView uri, QAnyStringView typeName)
1476 auto reportError = [&](QString msg) {
1478 error.setDescription(msg);
1479 m_state.errors.push_back(std::move(error));
1481 emit q->statusChanged(q->Error);
1483 auto emitComplete = [&]() {
1485 emit q->statusChanged(q->status());
1490 const QQmlType type = m_loadHelper->type();
1492 if (m_loadHelper->resolveTypeResult() == LoadHelper::ResolveTypeResult::NoSuchModule) {
1493 reportError(QLatin1String(R"(No module named "%1" found)").arg(uri.toString()));
1494 }
else if (!type.isValid()) {
1495 reportError(QLatin1String(R"(Module "%1" contains no type named "%2")")
1496 .arg(uri.toString(), typeName.toString()));
1497 }
else if (type.isCreatable()) {
1499 }
else if (type.isComposite()) {
1500 QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous;
1501 switch (m_loadHelper->mode()) {
1502 case QQmlTypeLoader::Asynchronous:
1503 mode = QQmlComponent::Asynchronous;
1505 case QQmlTypeLoader::PreferSynchronous:
1506 case QQmlTypeLoader::Synchronous:
1507 mode = QQmlComponent::PreferSynchronous;
1512 loadUrl(type.sourceUrl(), mode);
1513 }
else if (type.isInlineComponentType()) {
1514 auto baseUrl = type.sourceUrl();
1515 baseUrl.setFragment(QString());
1517 Q_ASSERT(m_progress == 0.0);
1521 QSignalBlocker blockSignals(q);
1523 loadUrl(baseUrl, QQmlComponent::PreferSynchronous);
1526 if (m_progress != 0.0)
1527 emit q->progressChanged(m_progress);
1533 QString elementName = type.elementName();
1534 if (m_compilationUnit->inlineComponentId(elementName) == -1) {
1535 QString realTypeName = typeName.toString();
1536 realTypeName.truncate(realTypeName.indexOf(u'.'));
1537 QString errorMessage = R"(Type "%1" from module "%2" contains no inline component named "%3".)"_L1.arg(
1538 realTypeName, uri.toString(), elementName);
1539 if (elementName == u"qml")
1540 errorMessage +=
" To load the type \"%1\", drop the \".qml\" extension."_L1.arg(realTypeName);
1541 reportError(std::move(errorMessage));
1543 m_inlineComponentName = std::make_unique<QString>(std::move(elementName));
1546 }
else if (type.isSingleton() || type.isCompositeSingleton()) {
1547 reportError(QLatin1String(R"(%1 is a singleton, and cannot be loaded)").arg(typeName.toString()));
1549 reportError(QLatin1String(
"Could not load %1, as the type is uncreatable").arg(typeName.toString()));
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1573void QQmlComponent::create(QQmlIncubator &incubator, QQmlContext *context, QQmlContext *forContext)
1578 context = d->m_engine->rootContext();
1580 QQmlRefPointer<QQmlContextData> contextData = QQmlContextData::get(context);
1581 QQmlRefPointer<QQmlContextData> forContextData =
1582 forContext ? QQmlContextData::get(forContext) : contextData;
1584 if (!contextData->isValid()) {
1585 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1589 if (contextData->engine() != d->m_engine) {
1590 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1595 qWarning(
"QQmlComponent: Component is not ready");
1600 QExplicitlySharedDataPointer<QQmlIncubatorPrivate> p(incubator.d);
1602 if (d->loadedType().isValid()) {
1606 p->incubateCppBasedComponent(
this, context);
1610 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(d->m_engine);
1612 p->compilationUnit = d->m_compilationUnit;
1613 p->enginePriv = enginePriv;
1614 p->creator.reset(
new QQmlObjectCreator(
1615 contextData, d->m_compilationUnit, d->m_creationContext,
1616 d->m_inlineComponentName ? *d->m_inlineComponentName : QString(), p.data()));
1617 p->subComponentToCreate = d->m_start;
1619 enginePriv->incubate(incubator, forContextData);
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645void QQmlComponent::setInitialProperties(QObject *object,
const QVariantMap &properties)
1648 d->setInitialProperties(object, properties);
1651bool QQmlComponentPrivate::setInitialProperties(QObject *object,
const QVariantMap &properties)
1654 for (
auto it = properties.constBegin(); it != properties.constEnd(); ++it) {
1655 if (it.key().contains(u'.')) {
1656 auto segments = it.key().split(u'.');
1657 QString description = u"Setting initial properties failed: Cannot initialize nested "_s
1659 if (segments.size() >= 2) {
1660 QString s = u" To set %1.%2 as an initial property, create %1, set its "_s
1661 u"property %2, and pass %1 as an initial property."_s;
1662 description += s.arg(segments[0], segments[1]);
1665 error.setUrl(m_url);
1666 error.setDescription(description);
1667 qmlWarning(object, error);
1672 result = setInitialProperty(object, it.key(), it.value()) && result;
1678
1679
1680
1681
1682
1683
1684void QQmlComponentPrivate::incubateObject(
1685 QQmlIncubator *incubationTask,
1686 QQmlComponent *component,
1688 const QQmlRefPointer<QQmlContextData> &context,
1689 const QQmlRefPointer<QQmlContextData> &forContext)
1691 QQmlIncubatorPrivate *incubatorPriv = QQmlIncubatorPrivate::get(incubationTask);
1692 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(engine);
1693 QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component);
1695 incubatorPriv->compilationUnit = componentPriv->m_compilationUnit;
1696 incubatorPriv->enginePriv = enginePriv;
1697 incubatorPriv->creator.reset(
new QQmlObjectCreator(
1698 context, componentPriv->m_compilationUnit, componentPriv->m_creationContext,
1699 m_inlineComponentName ? *m_inlineComponentName : QString()));
1701 if (m_start == -1) {
1702 if (
const QString *icName = componentPriv->m_inlineComponentName.get()) {
1703 m_start = m_compilationUnit->inlineComponentId(*icName);
1704 Q_ASSERT(m_start > 0);
1707 incubatorPriv->subComponentToCreate = componentPriv->m_start;
1709 enginePriv->incubate(*incubationTask, forContext);
1720#define QmlIncubatorObjectMembers(class, Member)
1721 Member(class, HeapValue, HeapValue, valuemapOrObject)
1722 Member(class, HeapValue, HeapValue, statusChanged)
1723 Member(class, Pointer, QmlContext *, qmlContext)
1724 Member(class, NoMark, QQmlComponentIncubator *, incubator)
1725 Member(class, NoMark, QV4QPointer<QObject>, parent)
1728 DECLARE_MARKOBJECTS(QmlIncubatorObject)
1730 void init(QQmlIncubator::IncubationMode = QQmlIncubator::Asynchronous);
1731 inline void destroy();
1761 incubatorObject.set(inc->internalClass->engine, inc);
1765 QV4::Scope scope(incubatorObject.engine());
1766 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1767 i->statusChanged(s);
1771 QV4::Scope scope(incubatorObject.engine());
1772 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1773 auto d = QQmlIncubatorPrivate::get(
this);
1774 i->setInitialState(o, d->requiredProperties());
1784 me->setParent(parent);
1785 typedef QQmlPrivate::AutoParentFunction APF;
1786 QList<APF> functions = QQmlMetaType::parentFunctions();
1788 bool needParent =
false;
1789 for (
int ii = 0; ii < functions.size(); ++ii) {
1790 QQmlPrivate::AutoParentResult res = functions.at(ii)(me, parent);
1791 if (res == QQmlPrivate::Parented) {
1794 }
else if (res == QQmlPrivate::IncompatibleParent) {
1799 qmlWarning(me) <<
"Created graphical object was not placed in the graphics scene.";
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
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
1846void QQmlComponentPrivate::setInitialProperties(
1847 QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext,
const QV4::Value &o,
1848 const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent,
1849 const QQmlObjectCreator *creator)
1851 QV4::Scope scope(engine);
1852 QV4::ScopedObject object(scope);
1853 QV4::ScopedObject valueMap(scope, v);
1854 QV4::ObjectIterator it(scope, valueMap, QV4::ObjectIterator::EnumerableOnly);
1855 QV4::ScopedString name(scope);
1856 QV4::ScopedValue val(scope);
1857 if (engine->hasException)
1861 QV4::ScopedStackFrame frame(scope, qmlContext ? qmlContext : engine->scriptContext());
1864 name = it.nextPropertyNameAsString(val);
1868 const QStringList properties = name->toQString().split(QLatin1Char(
'.'));
1869 bool isTopLevelProperty = properties.size() == 1;
1870 for (
int i = 0; i < properties.size() - 1; ++i) {
1871 name = engine->newString(properties.at(i));
1872 object = object->get(name);
1873 if (engine->hasException || !object) {
1877 if (engine->hasException) {
1878 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1883 error.setUrl(qmlContext ? qmlContext->qmlContext()->url() : QUrl());
1884 error.setDescription(QLatin1String(
"Cannot resolve property \"%1\".")
1885 .arg(properties.join(u'.')));
1886 qmlWarning(createdComponent, error);
1889 const QString lastProperty = properties.last();
1890 name = engine->newString(lastProperty);
1891 object->put(name, val);
1892 if (engine->hasException) {
1893 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1895 }
else if (isTopLevelProperty && requiredProperties) {
1896 auto prop = removePropertyFromRequired(createdComponent, name->toQString(),
1897 requiredProperties, engine->qmlEngine());
1900 removePendingQPropertyBinding(object, lastProperty, creator);
1903 engine->hasException =
false;
1906QQmlError QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(
const RequiredPropertyInfo &unsetRequiredProperty)
1909 QString description = QLatin1String(
"Required property %1 was not initialized").arg(unsetRequiredProperty.propertyName);
1910 switch (unsetRequiredProperty.aliasesToRequired.size()) {
1914 const auto info = unsetRequiredProperty.aliasesToRequired.first();
1915 description += QLatin1String(
"\nIt can be set via the alias property %1 from %2\n").arg(info.propertyName, info.fileUrl.toString());
1919 description += QLatin1String(
"\nIt can be set via one of the following alias properties:");
1920 for (
const auto &aliasInfo: unsetRequiredProperty.aliasesToRequired) {
1921 description += QLatin1String(
"\n- %1 (%2)").arg(aliasInfo.propertyName, aliasInfo.fileUrl.toString());
1923 description += QLatin1Char(
'\n');
1925 error.setDescription(description);
1926 error.setUrl(unsetRequiredProperty.fileUrl);
1927 error.setLine(qmlConvertSourceCoordinate<quint32,
int>(
1928 unsetRequiredProperty.location.line()));
1929 error.setColumn(qmlConvertSourceCoordinate<quint32,
int>(
1930 unsetRequiredProperty.location.column()));
1934#if QT_DEPRECATED_SINCE(6
, 3
)
1936
1937
1938void QQmlComponent::createObject(QQmlV4FunctionPtr args)
1941 Q_ASSERT(d->m_engine);
1944 qmlWarning(
this) <<
"Unsuitable arguments passed to createObject(). The first argument should "
1945 "be a QObject* or null, and the second argument should be a JavaScript "
1946 "object or a QVariantMap";
1948 QObject *parent =
nullptr;
1949 QV4::ExecutionEngine *v4 = args->v4engine();
1950 QV4::Scope scope(v4);
1951 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
1953 if (args->length() >= 1) {
1954 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
1956 parent = qobjectWrapper->object();
1959 if (args->length() >= 2) {
1960 QV4::ScopedValue v(scope, (*args)[1]);
1961 if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
1962 qmlWarning(
this) << tr(
"createObject: value is not an object");
1963 args->setReturnValue(QV4::Encode::null());
1969 QQmlContext *ctxt = creationContext();
1970 if (!ctxt) ctxt = d->m_engine->rootContext();
1972 QObject *rv = beginCreate(ctxt);
1975 args->setReturnValue(QV4::Encode::null());
1979 QQmlComponent_setQmlParent(rv, parent);
1981 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4, rv));
1982 Q_ASSERT(object->isObject());
1984 if (!valuemap->isUndefined()) {
1985 QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->qmlContext());
1986 QQmlComponentPrivate::setInitialProperties(
1987 v4, qmlContext, object, valuemap, d->m_state.requiredProperties(), rv,
1988 d->m_state.creator());
1990 if (d->m_state.hasUnsetRequiredProperties()) {
1991 QList<QQmlError> errors;
1992 for (
const auto &requiredProperty: std::as_const(*d->m_state.requiredProperties())) {
1993 errors.push_back(QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(requiredProperty));
1995 qmlWarning(rv, errors);
1996 args->setReturnValue(QV4::Encode::null());
2001 d->completeCreate();
2003 Q_ASSERT(QQmlData::get(rv));
2004 QQmlData::get(rv)->explicitIndestructibleSet =
false;
2005 QQmlData::get(rv)->indestructible =
false;
2007 args->setReturnValue(object->asReturnedValue());
2012
2013
2014QObject *QQmlComponent::createObject(QObject *parent,
const QVariantMap &properties)
2017 Q_ASSERT(d->m_engine);
2018 QObject *rv = d->createWithProperties(
2019 parent, properties, creationContext(), QQmlComponentPrivate::CreateBehavior::Qml);
2021 QQmlData *qmlData = QQmlData::get(rv);
2023 qmlData->explicitIndestructibleSet =
false;
2024 qmlData->indestructible =
false;
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
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
2085
2086
2087void QQmlComponent::incubateObject(QQmlV4FunctionPtr args)
2090 Q_ASSERT(d->m_engine);
2093 QV4::ExecutionEngine *v4 = args->v4engine();
2094 QV4::Scope scope(v4);
2096 QObject *parent =
nullptr;
2097 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
2098 QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous;
2100 if (args->length() >= 1) {
2101 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
2103 parent = qobjectWrapper->object();
2106 if (args->length() >= 2) {
2107 QV4::ScopedValue v(scope, (*args)[1]);
2109 }
else if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
2110 qmlWarning(
this) << tr(
"createObject: value is not an object");
2111 args->setReturnValue(QV4::Encode::null());
2118 if (args->length() >= 3) {
2119 QV4::ScopedValue val(scope, (*args)[2]);
2120 quint32 v = val->toUInt32();
2122 mode = QQmlIncubator::Asynchronous;
2124 mode = QQmlIncubator::AsynchronousIfNested;
2127 QQmlComponentExtension *e = componentExtension(args->v4engine());
2129 QV4::Scoped<QV4::QmlIncubatorObject> r(scope, v4->memoryManager->allocate<QV4::QmlIncubatorObject>(mode));
2130 QV4::ScopedObject p(scope, e->incubationProto.value());
2131 r->setPrototypeOf(p);
2133 if (!valuemap->isUndefined())
2134 r->d()->valuemapOrObject.set(scope.engine, valuemap);
2135 r->d()->qmlContext.set(scope.engine, v4->qmlContext());
2136 r->d()->parent = parent;
2138 QQmlIncubator *incubator = r->d()->incubator;
2139 create(*incubator, creationContext());
2141 if (incubator->status() == QQmlIncubator::Null) {
2142 args->setReturnValue(QV4::Encode::null());
2144 args->setReturnValue(r.asReturnedValue());
2149void QQmlComponentPrivate::initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext,
const QV4::Value &valuemap, QObject *toCreate, RequiredProperties *requiredProperties)
2151 QV4::ExecutionEngine *v4engine = m_engine->handle();
2152 QV4::Scope scope(v4engine);
2154 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate));
2155 Q_ASSERT(object->as<QV4::Object>());
2157 if (!valuemap.isUndefined()) {
2158 setInitialProperties(
2159 v4engine, qmlContext, object, valuemap, requiredProperties, toCreate, m_state.creator());
2163QQmlComponentExtension::QQmlComponentExtension(QV4::ExecutionEngine *v4)
2165 QV4::Scope scope(v4);
2166 QV4::ScopedObject proto(scope, v4->newObject());
2167 proto->defineAccessorProperty(QStringLiteral(
"onStatusChanged"),
2168 QV4::QmlIncubatorObject::method_get_statusChanged, QV4::QmlIncubatorObject::method_set_statusChanged);
2169 proto->defineAccessorProperty(QStringLiteral(
"status"), QV4::QmlIncubatorObject::method_get_status,
nullptr);
2170 proto->defineAccessorProperty(QStringLiteral(
"object"), QV4::QmlIncubatorObject::method_get_object,
nullptr);
2171 proto->defineDefaultProperty(QStringLiteral(
"forceCompletion"), QV4::QmlIncubatorObject::method_forceCompletion);
2173 incubationProto.set(v4, proto);
2176QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_object(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2178 QV4::Scope scope(b);
2179 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2183 return QV4::QObjectWrapper::wrap(scope.engine, o->d()->incubator->object());
2186QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_forceCompletion(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2188 QV4::Scope scope(b);
2189 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2193 o->d()->incubator->forceCompletion();
2198QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_status(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2200 QV4::Scope scope(b);
2201 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2205 return QV4::Encode(o->d()->incubator->status());
2208QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2210 QV4::Scope scope(b);
2211 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2215 return QV4::Encode(o->d()->statusChanged);
2218QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_set_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *argv,
int argc)
2220 QV4::Scope scope(b);
2221 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2225 o->d()->statusChanged.set(scope.engine, argv[0]);
2230QQmlComponentExtension::~QQmlComponentExtension()
2234void QV4::Heap::QmlIncubatorObject::init(QQmlIncubator::IncubationMode m)
2237 valuemapOrObject.set(internalClass->engine, QV4::Value::undefinedValue());
2238 statusChanged.set(internalClass->engine, QV4::Value::undefinedValue());
2240 qmlContext.set(internalClass->engine,
nullptr);
2241 incubator =
new QQmlComponentIncubator(
this, m);
2244void QV4::Heap::QmlIncubatorObject::destroy() {
2252 QQmlComponent_setQmlParent(o, d()->parent);
2254 if (!d()->valuemapOrObject.isUndefined()) {
2255 QV4::ExecutionEngine *v4 = engine();
2256 QV4::Scope scope(v4);
2257 QV4::ScopedObject obj(scope, QV4::QObjectWrapper::wrap(v4, o));
2258 QV4::Scoped<QV4::QmlContext> qmlCtxt(scope, d()->qmlContext);
2259 QQmlComponentPrivate::setInitialProperties(
2260 v4, qmlCtxt, obj, d()->valuemapOrObject, requiredProperties, o,
2261 QQmlIncubatorPrivate::get(d()->incubator)->creator.data());
2267 QV4::Scope scope(engine());
2269 QObject *object = d()->incubator->object();
2271 if (s == QQmlIncubator::Ready) {
2274 d()->valuemapOrObject.set(scope.engine, QV4::QObjectWrapper::wrap(scope.engine, object));
2276 QQmlData *ddata = QQmlData::get(object);
2278 ddata->explicitIndestructibleSet =
false;
2279 ddata->indestructible =
false;
2282 QV4::ScopedFunctionObject f(scope, d()->statusChanged);
2284 QV4::JSCallArguments jsCallData(scope, 1);
2285 *jsCallData.thisObject =
this;
2286 jsCallData.args[0] = QV4::Value::fromUInt32(s);
2287 f->call(jsCallData);
2288 if (scope.hasException()) {
2289 QQmlError error = scope.engine->catchExceptionAsQmlError();
2290 QQmlEnginePrivate::warning(QQmlEnginePrivate::get(scope.engine->qmlEngine()), error);
2294 if (s != QQmlIncubator::Loading)
2295 d()->incubator->incubatorObject.clear();
2298#undef INITIALPROPERTIES_SOURCE
2302#include "moc_qqmlcomponent.cpp"
2303#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)