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
729void QQmlComponent::setData(
const QByteArray &data,
const QUrl &url)
735 qWarning(
"QQmlComponent: Must provide an engine before calling setData");
743 QQmlRefPointer<QQmlTypeData> typeData = QQmlTypeLoader::get(d->m_engine)->getType(data, url);
745 if (typeData->isCompleteOrError()) {
746 d->fromTypeData(typeData);
748 d->m_typeData = typeData;
749 d->m_typeData->registerCallback(d);
753 emit statusChanged(status());
757
758
759
760QQmlContext *QQmlComponent::creationContext()
const
762 Q_D(
const QQmlComponent);
763 if (!d->m_creationContext.isNull())
764 return d->m_creationContext->asQQmlContext();
766 return qmlContext(
this);
770
771
772
773
774QQmlEngine *QQmlComponent::engine()
const
776 Q_D(
const QQmlComponent);
781
782
783
784
785void QQmlComponent::loadUrl(
const QUrl &url)
792
793
794
795
796
797void QQmlComponent::loadUrl(
const QUrl &url, QQmlComponent::CompilationMode mode)
800 d->loadUrl(url, mode);
803void QQmlComponentPrivate::loadUrl(
const QUrl &newUrl, QQmlComponent::CompilationMode mode)
808 if (newUrl.isRelative()) {
810 m_url = m_engine->baseUrl().resolved(QUrl(newUrl.toString()));
811 }
else if (m_engine->baseUrl().isLocalFile() && newUrl.isLocalFile() && !QDir::isAbsolutePath(newUrl.toLocalFile())) {
815 QUrl fixedUrl(newUrl);
816 fixedUrl.setScheme(QString());
819 m_url = m_engine->baseUrl().resolved(fixedUrl);
824 if (m_url.scheme() ==
"qrc"_L1 && !m_url.path().startsWith(
"/"_L1)) {
825 qWarning().nospace().noquote()
826 <<
"QQmlComponent: attempted to load via a relative URL '" << m_url.toString()
827 <<
"' in resource file system. This is not fully supported and may not work";
830 if (newUrl.isEmpty()) {
832 error.setDescription(QQmlComponent::tr(
"Invalid empty URL"));
833 m_state.errors.emplaceBack(error);
839 QQmlTypeLoader::Mode loaderMode = (mode == QQmlComponent::Asynchronous)
840 ? QQmlTypeLoader::Asynchronous
841 : QQmlTypeLoader::PreferSynchronous;
842 QQmlRefPointer<QQmlTypeData> data = QQmlTypeLoader::get(m_engine)->getType(m_url, loaderMode);
844 if (data->isCompleteOrError()) {
849 m_typeData->registerCallback(
this);
850 setProgress(data->progress());
853 emit q->statusChanged(q->status());
857
858
859
860QList<QQmlError> QQmlComponent::errors()
const
862 Q_D(
const QQmlComponent);
863 QList<QQmlError> errors;
864 errors.reserve(d->m_state.errors.size());
865 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors)
866 errors.emplaceBack(annotated.error);
871
872
873
874
875
876
877
878
879
882
883
884
885QString QQmlComponent::errorString()
const
887 Q_D(
const QQmlComponent);
891 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors) {
892 ret += annotated.error.toString() + QLatin1Char(
'\n');
898
899
900
903
904
905
906
907QUrl QQmlComponent::url()
const
909 Q_D(
const QQmlComponent);
914
915
916QQmlComponent::QQmlComponent(QQmlComponentPrivate &dd, QObject *parent)
917 : QObject(dd, parent)
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937QObject *QQmlComponent::create(QQmlContext *context)
940 return d->createWithProperties(
941 nullptr, QVariantMap {}, context, QQmlComponentPrivate::CreateBehavior::Cpp);
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964QObject *QQmlComponent::createWithInitialProperties(
965 const QVariantMap& initialProperties, QQmlContext *context)
968 return d->createWithProperties(
969 nullptr, initialProperties, context, QQmlComponentPrivate::CreateBehavior::Cpp);
975
976QObject *QQmlComponentPrivate::createWithProperties(
977 QObject *parent,
const QVariantMap &properties,
978 QQmlContext *context, CreateBehavior behavior)
982 QObject *rv = doBeginCreate(q, context);
984 if (m_state.isCompletePending()) {
988 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
989 complete(ep, &m_state);
995 QQmlComponent_setQmlParent(rv, parent);
997 if (behavior == CreateBehavior::Qml) {
999 for (
auto it = properties.cbegin(), end = properties.cend(); it != end; ++it)
1000 ok = setInitialProperty(rv, it.key(), it.value()) && ok;
1001 q->completeCreate();
1002 if (m_state.hasUnsetRequiredProperties()) {
1003 for (
const auto &unsetRequiredProperty : std::as_const(*m_state.requiredProperties())) {
1004 const QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1005 qmlWarning(rv, error);
1007 delete std::exchange(rv,
nullptr);
1010 delete std::exchange(rv,
nullptr);
1013 setInitialProperties(rv, properties);
1014 q->completeCreate();
1015 if (m_state.hasUnsetRequiredProperties())
1016 delete std::exchange(rv,
nullptr);
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059QObject *QQmlComponent::beginCreate(QQmlContext *context)
1063 return d->beginCreate(QQmlContextData::get(context));
1068 const int parserStatusCast = type.parserStatusCast();
1069 return parserStatusCast == -1
1071 :
reinterpret_cast<QQmlParserStatus *>(
reinterpret_cast<
char *>(rv) + parserStatusCast);
1074QObject *QQmlComponentPrivate::beginCreate(QQmlRefPointer<QQmlContextData> context)
1077 auto cleanup = qScopeGuard([
this] {
1078 if (!m_state.errors.isEmpty() && lcQmlComponentGeneral().isDebugEnabled()) {
1079 for (
const auto &e : std::as_const(m_state.errors)) {
1080 qCDebug(lcQmlComponentGeneral) <<
"QQmlComponent: " << e.error.toString();
1085 qWarning(
"QQmlComponent: Cannot create a component in a null context");
1089 if (!context->isValid()) {
1090 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1094 if (context->engine() != m_engine) {
1095 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1099 if (m_state.isCompletePending()) {
1100 qWarning(
"QQmlComponent: Cannot create new component instance before completing the previous");
1106 m_state.errors.removeIf([](
const auto &e) {
return e.isTransient; });
1107 m_state.clearRequiredProperties();
1109 if (!q->isReady()) {
1110 qWarning(
"QQmlComponent: Component is not ready");
1115 static const int maxCreationDepth = 10;
1116 if (creationDepth >= maxCreationDepth) {
1117 qWarning(
"QQmlComponent: Component creation is recursing - aborting");
1121 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(m_engine);
1123 enginePriv->inProgressCreations++;
1124 m_state.errors.clear();
1125 m_state.setCompletePending(
true);
1127 QObject *rv =
nullptr;
1129 const QQmlType type = loadedType();
1130 if (!type.isValid()) {
1131 enginePriv->referenceScarceResources();
1132 const QString *icName = m_inlineComponentName.get();
1133 m_state.initCreator(
1134 context, m_compilationUnit, m_creationContext, icName ? *icName : QString());
1136 QQmlObjectCreator::CreationFlags flags;
1138 flags = QQmlObjectCreator::InlineComponent;
1140 m_start = m_compilationUnit->inlineComponentId(*icName);
1141 Q_ASSERT(m_start > 0);
1143 flags = QQmlObjectCreator::NormalObject;
1146 rv = m_state.creator()->create(m_start,
nullptr,
nullptr, flags);
1148 m_state.appendCreatorErrors();
1149 enginePriv->dereferenceScarceResources();
1152 rv = type.createWithQQmlData();
1153 QQmlPropertyCache::ConstPtr propertyCache = QQmlData::ensurePropertyCache(rv);
1154 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv)) {
1155 parserStatus->classBegin();
1156 m_state.ensureRequiredPropertyStorage(rv);
1157 }
else if (type.finalizerCast() != -1) {
1158 m_state.ensureRequiredPropertyStorage(rv);
1161 if (propertyCache) {
1162 for (
int i = 0, propertyCount = propertyCache->propertyCount(); i < propertyCount; ++i) {
1163 if (
const QQmlPropertyData *propertyData = propertyCache->property(i); propertyData->isRequired()) {
1164 m_state.ensureRequiredPropertyStorage(rv);
1165 RequiredPropertyInfo info;
1166 info.propertyName = propertyData->name(rv);
1167 m_state.addPendingRequiredProperty(rv, propertyData, info);
1178 QQmlData *ddata = QQmlData::get(rv);
1182 ddata->indestructible =
true;
1183 ddata->explicitIndestructibleSet =
true;
1184 ddata->rootObjectInCreation =
false;
1187 if (!ddata->outerContext)
1188 ddata->outerContext = context.data();
1189 if (!ddata->context)
1190 ddata->context = context.data();
1196void QQmlComponentPrivate::beginDeferred(QQmlEnginePrivate *enginePriv,
1197 QObject *object, DeferredState *deferredState)
1199 QQmlData *ddata = QQmlData::get(object);
1200 Q_ASSERT(!ddata->deferredData.isEmpty());
1202 deferredState->reserve(ddata->deferredData.size());
1204 for (QQmlData::DeferredData *deferredData : std::as_const(ddata->deferredData)) {
1205 enginePriv->inProgressCreations++;
1207 ConstructionState state;
1208 state.setCompletePending(
true);
1210 auto creator = state.initCreator(
1211 deferredData->context->parent(),
1212 deferredData->compilationUnit,
1213 QQmlRefPointer<QQmlContextData>(),
1214 deferredData->inlineComponentName
1217 if (!creator->populateDeferredProperties(object, deferredData))
1218 state.appendCreatorErrors();
1219 deferredData->bindings.clear();
1221 deferredState->push_back(std::move(state));
1225void QQmlComponentPrivate::completeDeferred(QQmlEnginePrivate *enginePriv, QQmlComponentPrivate::DeferredState *deferredState)
1227 for (ConstructionState &state : *deferredState)
1228 complete(enginePriv, &state);
1231void QQmlComponentPrivate::complete(QQmlEnginePrivate *enginePriv, ConstructionState *state)
1233 if (state->isCompletePending()) {
1234 QQmlInstantiationInterrupt interrupt;
1235 state->creator()->finalize(interrupt);
1237 state->setCompletePending(
false);
1239 enginePriv->inProgressCreations--;
1241 if (0 == enginePriv->inProgressCreations) {
1242 while (enginePriv->erroredBindings) {
1243 enginePriv->warning(enginePriv->erroredBindings->removeError());
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266QQmlProperty QQmlComponentPrivate::removePropertyFromRequired(
1267 QObject *createdComponent,
const QString &name,
1268 RequiredProperties *requiredProperties, QQmlEngine *engine,
1269 bool *wasInRequiredProperties)
1271 Q_ASSERT(requiredProperties);
1272 QQmlProperty prop(createdComponent, name, engine);
1273 auto privProp = QQmlPropertyPrivate::get(prop);
1274 if (prop.isValid()) {
1276 const QQmlPropertyData *targetProp = &privProp->core;
1277 if (targetProp->isAlias()) {
1278 auto target = createdComponent;
1279 QQmlPropertyIndex originalIndex(targetProp->coreIndex());
1280 QQmlPropertyIndex propIndex;
1281 QQmlPropertyPrivate::findAliasTarget(target, originalIndex, &target, &propIndex);
1282 QQmlData *data = QQmlData::get(target);
1283 Q_ASSERT(data && data->propertyCache);
1284 targetProp = data->propertyCache->property(propIndex.coreIndex());
1288 QQmlData *data = QQmlData::get(createdComponent);
1289 Q_ASSERT(data && data->propertyCache);
1290 targetProp = data->propertyCache->property(targetProp->coreIndex());
1292 auto it = requiredProperties->constFind({createdComponent, targetProp});
1293 if (it != requiredProperties->cend()) {
1294 if (wasInRequiredProperties)
1295 *wasInRequiredProperties =
true;
1296 requiredProperties->erase(it);
1298 if (wasInRequiredProperties)
1299 *wasInRequiredProperties =
false;
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315void QQmlComponent::completeCreate()
1319 d->completeCreate();
1322void QQmlComponentPrivate::completeCreate()
1324 if (m_state.hasUnsetRequiredProperties()) {
1325 for (
const auto& unsetRequiredProperty: std::as_const(*m_state.requiredProperties())) {
1326 QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1327 m_state.errors.push_back(QQmlComponentPrivate::AnnotatedQmlError { error,
true });
1331 const QQmlType type = loadedType();
1332 if (type.isValid()) {
1333 QObject *rv = m_state.target();
1334 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv))
1335 parserStatus->componentComplete();
1337 if (
const int finalizerCast = type.finalizerCast(); finalizerCast != -1) {
1338 auto *hook =
reinterpret_cast<QQmlFinalizerHook *>(
1339 reinterpret_cast<
char *>(rv) + finalizerCast);
1340 hook->componentFinalized();
1344
1345
1346
1347
1348 m_state.setCompletePending(
false);
1349 QQmlEnginePrivate::get(m_engine)->inProgressCreations--;
1350 }
else if (m_state.isCompletePending()) {
1352 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
1353 complete(ep, &m_state);
1358QQmlComponentAttached::QQmlComponentAttached(QObject *parent)
1359: QObject(parent), m_prev(
nullptr), m_next(
nullptr)
1363QQmlComponentAttached::~QQmlComponentAttached()
1365 if (m_prev) *m_prev = m_next;
1366 if (m_next) m_next->m_prev = m_prev;
1372
1373
1374QQmlComponentAttached *QQmlComponent::qmlAttachedProperties(QObject *obj)
1376 QQmlComponentAttached *a =
new QQmlComponentAttached(obj);
1378 QQmlEngine *engine = qmlEngine(obj);
1382 QQmlEnginePrivate *p = QQmlEnginePrivate::get(engine);
1383 if (p->activeObjectCreator) {
1384 a->insertIntoList(p->activeObjectCreator->componentAttachment());
1386 QQmlData *d = QQmlData::get(obj);
1388 Q_ASSERT(d->context);
1389 d->context->addComponentAttached(a);
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412void QQmlComponent::loadFromModule(QAnyStringView uri, QAnyStringView typeName,
1413 QQmlComponent::CompilationMode mode)
1417 QQmlTypeLoader::Mode typeLoaderMode = QQmlTypeLoader::Synchronous;
1419 case QQmlComponent::PreferSynchronous:
1420 typeLoaderMode = QQmlTypeLoader::PreferSynchronous;
1422 case QQmlComponent::Asynchronous:
1423 typeLoaderMode = QQmlTypeLoader::Asynchronous;
1427 d->prepareLoadFromModule(uri, typeName, typeLoaderMode);
1428 if (d->m_loadHelper->isCompleteOrError())
1429 d->completeLoadFromModule(uri, typeName);
1431 d->m_loadHelper->registerCallback(d);
1434void QQmlComponentPrivate::prepareLoadFromModule(
1435 QAnyStringView uri, QAnyStringView typeName, QQmlTypeLoader::Mode mode)
1439 m_loadHelper->unregisterCallback(
this);
1442 m_loadHelper = QQml::makeRefPointer<LoadHelper>(QQmlTypeLoader::get(m_engine), uri, typeName, mode);
1445void QQmlComponentPrivate::completeLoadFromModule(QAnyStringView uri, QAnyStringView typeName)
1450 auto reportError = [&](QString msg) {
1452 error.setDescription(msg);
1453 m_state.errors.push_back(std::move(error));
1455 emit q->statusChanged(q->Error);
1457 auto emitComplete = [&]() {
1459 emit q->statusChanged(q->status());
1464 const QQmlType type = m_loadHelper->type();
1466 if (m_loadHelper->resolveTypeResult() == LoadHelper::ResolveTypeResult::NoSuchModule) {
1467 reportError(QLatin1String(R"(No module named "%1" found)").arg(uri.toString()));
1468 }
else if (!type.isValid()) {
1469 reportError(QLatin1String(R"(Module "%1" contains no type named "%2")")
1470 .arg(uri.toString(), typeName.toString()));
1471 }
else if (type.isCreatable()) {
1473 }
else if (type.isComposite()) {
1474 QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous;
1475 switch (m_loadHelper->mode()) {
1476 case QQmlTypeLoader::Asynchronous:
1477 mode = QQmlComponent::Asynchronous;
1479 case QQmlTypeLoader::PreferSynchronous:
1480 case QQmlTypeLoader::Synchronous:
1481 mode = QQmlComponent::PreferSynchronous;
1486 loadUrl(type.sourceUrl(), mode);
1487 }
else if (type.isInlineComponentType()) {
1488 auto baseUrl = type.sourceUrl();
1489 baseUrl.setFragment(QString());
1491 Q_ASSERT(m_progress == 0.0);
1495 QSignalBlocker blockSignals(q);
1497 loadUrl(baseUrl, QQmlComponent::PreferSynchronous);
1500 if (m_progress != 0.0)
1501 emit q->progressChanged(m_progress);
1507 QString elementName = type.elementName();
1508 if (m_compilationUnit->inlineComponentId(elementName) == -1) {
1509 QString realTypeName = typeName.toString();
1510 realTypeName.truncate(realTypeName.indexOf(u'.'));
1511 QString errorMessage = R"(Type "%1" from module "%2" contains no inline component named "%3".)"_L1.arg(
1512 realTypeName, uri.toString(), elementName);
1513 if (elementName == u"qml")
1514 errorMessage +=
" To load the type \"%1\", drop the \".qml\" extension."_L1.arg(realTypeName);
1515 reportError(std::move(errorMessage));
1517 m_inlineComponentName = std::make_unique<QString>(std::move(elementName));
1520 }
else if (type.isSingleton() || type.isCompositeSingleton()) {
1521 reportError(QLatin1String(R"(%1 is a singleton, and cannot be loaded)").arg(typeName.toString()));
1523 reportError(QLatin1String(
"Could not load %1, as the type is uncreatable").arg(typeName.toString()));
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1547void QQmlComponent::create(QQmlIncubator &incubator, QQmlContext *context, QQmlContext *forContext)
1552 context = d->m_engine->rootContext();
1554 QQmlRefPointer<QQmlContextData> contextData = QQmlContextData::get(context);
1555 QQmlRefPointer<QQmlContextData> forContextData =
1556 forContext ? QQmlContextData::get(forContext) : contextData;
1558 if (!contextData->isValid()) {
1559 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1563 if (contextData->engine() != d->m_engine) {
1564 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1569 qWarning(
"QQmlComponent: Component is not ready");
1574 QExplicitlySharedDataPointer<QQmlIncubatorPrivate> p(incubator.d);
1576 if (d->loadedType().isValid()) {
1580 p->incubateCppBasedComponent(
this, context);
1584 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(d->m_engine);
1586 p->compilationUnit = d->m_compilationUnit;
1587 p->enginePriv = enginePriv;
1588 p->creator.reset(
new QQmlObjectCreator(
1589 contextData, d->m_compilationUnit, d->m_creationContext,
1590 d->m_inlineComponentName ? *d->m_inlineComponentName : QString(), p.data()));
1591 p->subComponentToCreate = d->m_start;
1593 enginePriv->incubate(incubator, forContextData);
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619void QQmlComponent::setInitialProperties(QObject *object,
const QVariantMap &properties)
1622 d->setInitialProperties(object, properties);
1625bool QQmlComponentPrivate::setInitialProperties(QObject *object,
const QVariantMap &properties)
1628 for (
auto it = properties.constBegin(); it != properties.constEnd(); ++it) {
1629 if (it.key().contains(u'.')) {
1630 auto segments = it.key().split(u'.');
1631 QString description = u"Setting initial properties failed: Cannot initialize nested "_s
1633 if (segments.size() >= 2) {
1634 QString s = u" To set %1.%2 as an initial property, create %1, set its "_s
1635 u"property %2, and pass %1 as an initial property."_s;
1636 description += s.arg(segments[0], segments[1]);
1639 error.setUrl(m_url);
1640 error.setDescription(description);
1641 qmlWarning(object, error);
1646 result = setInitialProperty(object, it.key(), it.value()) && result;
1652
1653
1654
1655
1656
1657
1658void QQmlComponentPrivate::incubateObject(
1659 QQmlIncubator *incubationTask,
1660 QQmlComponent *component,
1662 const QQmlRefPointer<QQmlContextData> &context,
1663 const QQmlRefPointer<QQmlContextData> &forContext)
1665 QQmlIncubatorPrivate *incubatorPriv = QQmlIncubatorPrivate::get(incubationTask);
1666 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(engine);
1667 QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component);
1669 incubatorPriv->compilationUnit = componentPriv->m_compilationUnit;
1670 incubatorPriv->enginePriv = enginePriv;
1671 incubatorPriv->creator.reset(
new QQmlObjectCreator(
1672 context, componentPriv->m_compilationUnit, componentPriv->m_creationContext,
1673 m_inlineComponentName ? *m_inlineComponentName : QString()));
1675 if (m_start == -1) {
1676 if (
const QString *icName = componentPriv->m_inlineComponentName.get()) {
1677 m_start = m_compilationUnit->inlineComponentId(*icName);
1678 Q_ASSERT(m_start > 0);
1681 incubatorPriv->subComponentToCreate = componentPriv->m_start;
1683 enginePriv->incubate(*incubationTask, forContext);
1694#define QmlIncubatorObjectMembers(class, Member)
1695 Member(class, HeapValue, HeapValue, valuemapOrObject)
1696 Member(class, HeapValue, HeapValue, statusChanged)
1697 Member(class, Pointer, QmlContext *, qmlContext)
1698 Member(class, NoMark, QQmlComponentIncubator *, incubator)
1699 Member(class, NoMark, QV4QPointer<QObject>, parent)
1702 DECLARE_MARKOBJECTS(QmlIncubatorObject)
1704 void init(QQmlIncubator::IncubationMode = QQmlIncubator::Asynchronous);
1705 inline void destroy();
1735 incubatorObject.set(inc->internalClass->engine, inc);
1739 QV4::Scope scope(incubatorObject.engine());
1740 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1741 i->statusChanged(s);
1745 QV4::Scope scope(incubatorObject.engine());
1746 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1747 auto d = QQmlIncubatorPrivate::get(
this);
1748 i->setInitialState(o, d->requiredProperties());
1758 me->setParent(parent);
1759 typedef QQmlPrivate::AutoParentFunction APF;
1760 QList<APF> functions = QQmlMetaType::parentFunctions();
1762 bool needParent =
false;
1763 for (
int ii = 0; ii < functions.size(); ++ii) {
1764 QQmlPrivate::AutoParentResult res = functions.at(ii)(me, parent);
1765 if (res == QQmlPrivate::Parented) {
1768 }
else if (res == QQmlPrivate::IncompatibleParent) {
1773 qmlWarning(me) <<
"Created graphical object was not placed in the graphics scene.";
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1820void QQmlComponentPrivate::setInitialProperties(
1821 QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext,
const QV4::Value &o,
1822 const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent,
1823 const QQmlObjectCreator *creator)
1825 QV4::Scope scope(engine);
1826 QV4::ScopedObject object(scope);
1827 QV4::ScopedObject valueMap(scope, v);
1828 QV4::ObjectIterator it(scope, valueMap, QV4::ObjectIterator::EnumerableOnly);
1829 QV4::ScopedString name(scope);
1830 QV4::ScopedValue val(scope);
1831 if (engine->hasException)
1835 QV4::ScopedStackFrame frame(scope, qmlContext ? qmlContext : engine->scriptContext());
1838 name = it.nextPropertyNameAsString(val);
1842 const QStringList properties = name->toQString().split(QLatin1Char(
'.'));
1843 bool isTopLevelProperty = properties.size() == 1;
1844 for (
int i = 0; i < properties.size() - 1; ++i) {
1845 name = engine->newString(properties.at(i));
1846 object = object->get(name);
1847 if (engine->hasException || !object) {
1851 if (engine->hasException) {
1852 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1857 error.setUrl(qmlContext ? qmlContext->qmlContext()->url() : QUrl());
1858 error.setDescription(QLatin1String(
"Cannot resolve property \"%1\".")
1859 .arg(properties.join(u'.')));
1860 qmlWarning(createdComponent, error);
1863 const QString lastProperty = properties.last();
1864 name = engine->newString(lastProperty);
1865 object->put(name, val);
1866 if (engine->hasException) {
1867 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1869 }
else if (isTopLevelProperty && requiredProperties) {
1870 auto prop = removePropertyFromRequired(createdComponent, name->toQString(),
1871 requiredProperties, engine->qmlEngine());
1874 removePendingQPropertyBinding(object, lastProperty, creator);
1877 engine->hasException =
false;
1880QQmlError QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(
const RequiredPropertyInfo &unsetRequiredProperty)
1883 QString description = QLatin1String(
"Required property %1 was not initialized").arg(unsetRequiredProperty.propertyName);
1884 switch (unsetRequiredProperty.aliasesToRequired.size()) {
1888 const auto info = unsetRequiredProperty.aliasesToRequired.first();
1889 description += QLatin1String(
"\nIt can be set via the alias property %1 from %2\n").arg(info.propertyName, info.fileUrl.toString());
1893 description += QLatin1String(
"\nIt can be set via one of the following alias properties:");
1894 for (
auto aliasInfo: unsetRequiredProperty.aliasesToRequired) {
1895 description += QLatin1String(
"\n- %1 (%2)").arg(aliasInfo.propertyName, aliasInfo.fileUrl.toString());
1897 description += QLatin1Char(
'\n');
1899 error.setDescription(description);
1900 error.setUrl(unsetRequiredProperty.fileUrl);
1901 error.setLine(qmlConvertSourceCoordinate<quint32,
int>(
1902 unsetRequiredProperty.location.line()));
1903 error.setColumn(qmlConvertSourceCoordinate<quint32,
int>(
1904 unsetRequiredProperty.location.column()));
1908#if QT_DEPRECATED_SINCE(6
, 3
)
1910
1911
1912void QQmlComponent::createObject(QQmlV4FunctionPtr args)
1915 Q_ASSERT(d->m_engine);
1918 qmlWarning(
this) <<
"Unsuitable arguments passed to createObject(). The first argument should "
1919 "be a QObject* or null, and the second argument should be a JavaScript "
1920 "object or a QVariantMap";
1922 QObject *parent =
nullptr;
1923 QV4::ExecutionEngine *v4 = args->v4engine();
1924 QV4::Scope scope(v4);
1925 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
1927 if (args->length() >= 1) {
1928 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
1930 parent = qobjectWrapper->object();
1933 if (args->length() >= 2) {
1934 QV4::ScopedValue v(scope, (*args)[1]);
1935 if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
1936 qmlWarning(
this) << tr(
"createObject: value is not an object");
1937 args->setReturnValue(QV4::Encode::null());
1943 QQmlContext *ctxt = creationContext();
1944 if (!ctxt) ctxt = d->m_engine->rootContext();
1946 QObject *rv = beginCreate(ctxt);
1949 args->setReturnValue(QV4::Encode::null());
1953 QQmlComponent_setQmlParent(rv, parent);
1955 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4, rv));
1956 Q_ASSERT(object->isObject());
1958 if (!valuemap->isUndefined()) {
1959 QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->qmlContext());
1960 QQmlComponentPrivate::setInitialProperties(
1961 v4, qmlContext, object, valuemap, d->m_state.requiredProperties(), rv,
1962 d->m_state.creator());
1964 if (d->m_state.hasUnsetRequiredProperties()) {
1965 QList<QQmlError> errors;
1966 for (
const auto &requiredProperty: std::as_const(*d->m_state.requiredProperties())) {
1967 errors.push_back(QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(requiredProperty));
1969 qmlWarning(rv, errors);
1970 args->setReturnValue(QV4::Encode::null());
1975 d->completeCreate();
1977 Q_ASSERT(QQmlData::get(rv));
1978 QQmlData::get(rv)->explicitIndestructibleSet =
false;
1979 QQmlData::get(rv)->indestructible =
false;
1981 args->setReturnValue(object->asReturnedValue());
1986
1987
1988QObject *QQmlComponent::createObject(QObject *parent,
const QVariantMap &properties)
1991 Q_ASSERT(d->m_engine);
1992 QObject *rv = d->createWithProperties(
1993 parent, properties, creationContext(), QQmlComponentPrivate::CreateBehavior::Qml);
1995 QQmlData *qmlData = QQmlData::get(rv);
1997 qmlData->explicitIndestructibleSet =
false;
1998 qmlData->indestructible =
false;
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
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
2059
2060
2061void QQmlComponent::incubateObject(QQmlV4FunctionPtr args)
2064 Q_ASSERT(d->m_engine);
2067 QV4::ExecutionEngine *v4 = args->v4engine();
2068 QV4::Scope scope(v4);
2070 QObject *parent =
nullptr;
2071 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
2072 QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous;
2074 if (args->length() >= 1) {
2075 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
2077 parent = qobjectWrapper->object();
2080 if (args->length() >= 2) {
2081 QV4::ScopedValue v(scope, (*args)[1]);
2083 }
else if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
2084 qmlWarning(
this) << tr(
"createObject: value is not an object");
2085 args->setReturnValue(QV4::Encode::null());
2092 if (args->length() >= 3) {
2093 QV4::ScopedValue val(scope, (*args)[2]);
2094 quint32 v = val->toUInt32();
2096 mode = QQmlIncubator::Asynchronous;
2098 mode = QQmlIncubator::AsynchronousIfNested;
2101 QQmlComponentExtension *e = componentExtension(args->v4engine());
2103 QV4::Scoped<QV4::QmlIncubatorObject> r(scope, v4->memoryManager->allocate<QV4::QmlIncubatorObject>(mode));
2104 QV4::ScopedObject p(scope, e->incubationProto.value());
2105 r->setPrototypeOf(p);
2107 if (!valuemap->isUndefined())
2108 r->d()->valuemapOrObject.set(scope.engine, valuemap);
2109 r->d()->qmlContext.set(scope.engine, v4->qmlContext());
2110 r->d()->parent = parent;
2112 QQmlIncubator *incubator = r->d()->incubator;
2113 create(*incubator, creationContext());
2115 if (incubator->status() == QQmlIncubator::Null) {
2116 args->setReturnValue(QV4::Encode::null());
2118 args->setReturnValue(r.asReturnedValue());
2123void QQmlComponentPrivate::initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext,
const QV4::Value &valuemap, QObject *toCreate, RequiredProperties *requiredProperties)
2125 QV4::ExecutionEngine *v4engine = m_engine->handle();
2126 QV4::Scope scope(v4engine);
2128 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate));
2129 Q_ASSERT(object->as<QV4::Object>());
2131 if (!valuemap.isUndefined()) {
2132 setInitialProperties(
2133 v4engine, qmlContext, object, valuemap, requiredProperties, toCreate, m_state.creator());
2137QQmlComponentExtension::QQmlComponentExtension(QV4::ExecutionEngine *v4)
2139 QV4::Scope scope(v4);
2140 QV4::ScopedObject proto(scope, v4->newObject());
2141 proto->defineAccessorProperty(QStringLiteral(
"onStatusChanged"),
2142 QV4::QmlIncubatorObject::method_get_statusChanged, QV4::QmlIncubatorObject::method_set_statusChanged);
2143 proto->defineAccessorProperty(QStringLiteral(
"status"), QV4::QmlIncubatorObject::method_get_status,
nullptr);
2144 proto->defineAccessorProperty(QStringLiteral(
"object"), QV4::QmlIncubatorObject::method_get_object,
nullptr);
2145 proto->defineDefaultProperty(QStringLiteral(
"forceCompletion"), QV4::QmlIncubatorObject::method_forceCompletion);
2147 incubationProto.set(v4, proto);
2150QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_object(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2152 QV4::Scope scope(b);
2153 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2157 return QV4::QObjectWrapper::wrap(scope.engine, o->d()->incubator->object());
2160QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_forceCompletion(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2162 QV4::Scope scope(b);
2163 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2167 o->d()->incubator->forceCompletion();
2172QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_status(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2174 QV4::Scope scope(b);
2175 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2179 return QV4::Encode(o->d()->incubator->status());
2182QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2184 QV4::Scope scope(b);
2185 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2189 return QV4::Encode(o->d()->statusChanged);
2192QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_set_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *argv,
int argc)
2194 QV4::Scope scope(b);
2195 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2199 o->d()->statusChanged.set(scope.engine, argv[0]);
2204QQmlComponentExtension::~QQmlComponentExtension()
2208void QV4::Heap::QmlIncubatorObject::init(QQmlIncubator::IncubationMode m)
2211 valuemapOrObject.set(internalClass->engine, QV4::Value::undefinedValue());
2212 statusChanged.set(internalClass->engine, QV4::Value::undefinedValue());
2214 qmlContext.set(internalClass->engine,
nullptr);
2215 incubator =
new QQmlComponentIncubator(
this, m);
2218void QV4::Heap::QmlIncubatorObject::destroy() {
2226 QQmlComponent_setQmlParent(o, d()->parent);
2228 if (!d()->valuemapOrObject.isUndefined()) {
2229 QV4::ExecutionEngine *v4 = engine();
2230 QV4::Scope scope(v4);
2231 QV4::ScopedObject obj(scope, QV4::QObjectWrapper::wrap(v4, o));
2232 QV4::Scoped<QV4::QmlContext> qmlCtxt(scope, d()->qmlContext);
2233 QQmlComponentPrivate::setInitialProperties(
2234 v4, qmlCtxt, obj, d()->valuemapOrObject, requiredProperties, o,
2235 QQmlIncubatorPrivate::get(d()->incubator)->creator.data());
2241 QV4::Scope scope(engine());
2243 QObject *object = d()->incubator->object();
2245 if (s == QQmlIncubator::Ready) {
2248 d()->valuemapOrObject.set(scope.engine, QV4::QObjectWrapper::wrap(scope.engine, object));
2250 QQmlData *ddata = QQmlData::get(object);
2252 ddata->explicitIndestructibleSet =
false;
2253 ddata->indestructible =
false;
2256 QV4::ScopedFunctionObject f(scope, d()->statusChanged);
2258 QV4::JSCallArguments jsCallData(scope, 1);
2259 *jsCallData.thisObject =
this;
2260 jsCallData.args[0] = QV4::Value::fromUInt32(s);
2261 f->call(jsCallData);
2262 if (scope.hasException()) {
2263 QQmlError error = scope.engine->catchExceptionAsQmlError();
2264 QQmlEnginePrivate::warning(QQmlEnginePrivate::get(scope.engine->qmlEngine()), error);
2268 if (s != QQmlIncubator::Loading)
2269 d()->incubator->incubatorObject.clear();
2272#undef INITIALPROPERTIES_SOURCE
2276#include "moc_qqmlcomponent.cpp"
2277#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)