14#include <private/qqmljavascriptexpression_p.h>
15#include <private/qqmlsourcecoordinate_p.h>
17#include <private/qv4functionobject_p.h>
18#include <private/qv4script_p.h>
19#include <private/qv4scopedvalue_p.h>
20#include <private/qv4objectiterator_p.h>
21#include <private/qv4qobjectwrapper_p.h>
22#include <private/qv4jscall_p.h>
27#include <QThreadStorage>
28#include <QtCore/qdebug.h>
29#include <QtCore/qloggingcategory.h>
33using namespace Qt::Literals::StringLiterals;
36 Q_CONSTINIT
thread_local int creationDepth = 0;
43class QQmlComponentExtension :
public QV4::ExecutionEngine::Deletable
46 QQmlComponentExtension(QV4::ExecutionEngine *v4);
47 virtual ~QQmlComponentExtension();
49 QV4::PersistentValue incubationProto;
54
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
156
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
272
273
274
275
276
277
278
279
280
283
284
285
286
287
288
289
290
292void QQmlComponentPrivate::ready(QQmlNotifyingBlob *)
296 Q_ASSERT(m_typeData);
298 fromTypeData(m_typeData);
301 emit q->statusChanged(q->status());
304void QQmlComponentPrivate::progress(QQmlNotifyingBlob *, qreal p)
309void QQmlComponentPrivate::fromTypeData(
const QQmlRefPointer<QQmlTypeData> &data)
311 m_url = data->finalUrl();
312 if (
auto cu = data->compilationUnit())
313 m_compilationUnit = m_engine->handle()->executableCompilationUnit(std::move(cu));
315 if (!m_compilationUnit) {
316 Q_ASSERT(data->isError());
317 m_state.errors.clear();
318 m_state.appendErrors(data->errors());
322bool QQmlComponentPrivate::hadTopLevelRequiredProperties()
const
324 return m_state.creator()->componentHadTopLevelRequiredProperties();
327void QQmlComponentPrivate::clear()
330 m_typeData->unregisterCallback(
this);
335 m_loadHelper->unregisterCallback(
this);
336 m_loadHelper.reset();
339 m_compilationUnit.reset();
340 m_inlineComponentName.reset();
343QObject *QQmlComponentPrivate::doBeginCreate(QQmlComponent *q, QQmlContext *context)
347 qWarning(
"QQmlComponent: Must provide an engine before calling create");
351 context = m_engine->rootContext();
352 return q->beginCreate(context);
356 QV4::Value *object,
const QString &propertyName,
const QQmlObjectCreator *creator)
361 QV4::QObjectWrapper *wrapper = object->as<QV4::QObjectWrapper>();
365 QObject *o = wrapper->object();
369 if (QQmlData *ddata = QQmlData::get(o)) {
371 propertyName, o, ddata->outerContext);
372 if (propData && propData->acceptsQBinding())
373 creator->removePendingBinding(o, propData->coreIndex());
377 const QMetaObject *meta = o->metaObject();
379 const int index = meta->indexOfProperty(propertyName.toUtf8());
380 if (index != -1 && meta->property(index).isBindable())
381 creator->removePendingBinding(o, index);
384bool QQmlComponentPrivate::setInitialProperty(
385 QObject *base,
const QString &name,
const QVariant &value)
387 bool isComplexProperty = name.contains(u'.');
390 if (m_state.hasUnsetRequiredProperties() && !isComplexProperty)
391 prop = QQmlComponentPrivate::removePropertyFromRequired(
392 base, name, m_state.requiredProperties(), m_engine);
393 else if (QQmlContext *ctxt = qmlContext(base); ctxt)
394 prop = QQmlProperty(base, name, ctxt);
396 prop = QQmlProperty(base, name, m_engine);
398 if (!prop.isValid()) {
402 if (!isComplexProperty)
406 const QStringList properties = name.split(u'.');
407 QV4::Scope scope(m_engine->handle());
408 QV4::ScopedObject object(scope, QV4::QObjectWrapper::wrap(scope.engine, base));
409 QV4::ScopedString segment(scope);
410 for (
int i = 0; i < properties.size() - 1; ++i) {
411 segment = scope.engine->newString(properties.at(i));
412 object = object->get(segment);
413 if (scope.engine->hasException || object->isNullOrUndefined())
417 const QString lastProperty = properties.last();
418 if (!object->isNullOrUndefined()) {
419 segment = scope.engine->newString(lastProperty);
420 QV4::ScopedValue v(scope, scope.engine->metaTypeToJS(value.metaType(), value.constData()));
421 object->put(segment, v);
426 if (scope.engine->hasException) {
427 qmlWarning(base, scope.engine->catchExceptionAsQmlError());
428 scope.engine->hasException =
false;
432 removePendingQPropertyBinding(object, lastProperty, m_state.creator());
436 if (QQmlPropertyPrivate::get(prop)->writeValueProperty(value, {})) {
437 if (prop.isBindable()) {
438 if (QQmlObjectCreator *creator = m_state.creator())
439 creator->removePendingBinding(prop.object(), prop.index());
446 error.setDescription(QStringLiteral(
"Could not set initial property %1").arg(name));
447 qmlWarning(base, error);
452
453
454QQmlComponent::QQmlComponent(QObject *parent)
455 : QObject(*(
new QQmlComponentPrivate), parent)
460
461
462QQmlComponent::~QQmlComponent()
466 if (d->m_state.isCompletePending()) {
467 qWarning(
"QQmlComponent: Component destroyed while completion pending");
470 qWarning() <<
"This may have been caused by one of the following errors:";
471 for (
const QQmlComponentPrivate::AnnotatedQmlError &e : std::as_const(d->m_state.errors))
472 qWarning().nospace().noquote() << QLatin1String(
" ") << e.error;
476 if (d->m_state.hasCreator())
481 d->m_typeData->unregisterCallback(d);
482 if (d->m_engine && !d->m_typeData->isCompleteOrError()) {
485 QQmlTypeLoader::get(d->m_engine)->drop(QQmlDataBlob::Ptr(d->m_typeData.data()));
487 d->m_typeData.reset();
492
493
494
495
496
497
498
499
500
501
502
505
506
507
508QQmlComponent::Status QQmlComponent::status()
const
510 Q_D(
const QQmlComponent);
514 else if (!d->m_state.errors.isEmpty())
516 else if (d->m_engine && (d->m_compilationUnit || d->loadedType().isValid()))
518 else if (d->m_loadHelper)
525
526
527bool QQmlComponent::isNull()
const
529 return status() == Null;
533
534
535bool QQmlComponent::isReady()
const
537 return status() == Ready;
541
542
543bool QQmlComponent::isError()
const
545 return status() == Error;
549
550
551bool QQmlComponent::isLoading()
const
553 return status() == Loading;
557
558
559
560
561
562bool QQmlComponent::isBound()
const
564 Q_D(
const QQmlComponent);
569
570
571
572
575
576
577
578
579qreal QQmlComponent::progress()
const
581 Q_D(
const QQmlComponent);
582 return d->m_progress;
586
587
588
589
590
593
594
595
596
597
600
601
602
603QQmlComponent::QQmlComponent(QQmlEngine *engine, QObject *parent)
604 : QObject(*(
new QQmlComponentPrivate), parent)
607 d->m_engine = engine;
608 QObject::connect(engine, &QObject::destroyed,
this, [d]() {
610 d->m_engine =
nullptr;
615
616
617
618
619
620
621
622QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QUrl &url, QObject *parent)
623 : QQmlComponent(engine, url, QQmlComponent::PreferSynchronous, parent)
628
629
630
631
632
633
634
635
636QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QUrl &url, CompilationMode mode,
638 : QQmlComponent(engine, parent)
641 d->loadUrl(url, mode);
645
646
647
648
649
650
651
652
653QQmlComponent::QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, QObject *parent)
654 : QQmlComponent(engine, uri, typeName, QQmlComponent::PreferSynchronous, parent)
660
661
662
663
664
665
666
667
668QQmlComponent::QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, CompilationMode mode, QObject *parent)
669 : QQmlComponent(engine, parent)
671 loadFromModule(uri, typeName, mode);
675
676
677
678
679
680QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QString &fileName,
682 : QQmlComponent(engine, fileName, QQmlComponent::PreferSynchronous, parent)
687
688
689
690
691
692
693QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QString &fileName,
694 CompilationMode mode, QObject *parent)
695 : QQmlComponent(engine, parent)
698 if (fileName.startsWith(u':'))
699 d->loadUrl(QUrl(QLatin1String(
"qrc") + fileName), mode);
700 else if (QDir::isAbsolutePath(fileName))
701 d->loadUrl(QUrl::fromLocalFile(fileName), mode);
703 d->loadUrl(QUrl(fileName), mode);
707
708
709QQmlComponent::QQmlComponent(QQmlEngine *engine, QV4::ExecutableCompilationUnit *compilationUnit,
710 int start, QObject *parent)
711 : QQmlComponent(engine, parent)
714 d->m_compilationUnit.reset(compilationUnit);
716 d->m_url = compilationUnit->finalUrl();
721
722
723
724
725
726
727
728void QQmlComponent::setData(
const QByteArray &data,
const QUrl &url)
734 qWarning(
"QQmlComponent: Must provide an engine before calling setData");
742 QQmlRefPointer<QQmlTypeData> typeData = QQmlTypeLoader::get(d->m_engine)->getType(data, url);
744 if (typeData->isCompleteOrError()) {
745 d->fromTypeData(typeData);
747 d->m_typeData = typeData;
748 d->m_typeData->registerCallback(d);
752 emit statusChanged(status());
756
757
758
759QQmlContext *QQmlComponent::creationContext()
const
761 Q_D(
const QQmlComponent);
762 if (!d->m_creationContext.isNull())
763 return d->m_creationContext->asQQmlContext();
765 return qmlContext(
this);
769
770
771
772
773QQmlEngine *QQmlComponent::engine()
const
775 Q_D(
const QQmlComponent);
780
781
782
783
784void QQmlComponent::loadUrl(
const QUrl &url)
791
792
793
794
795
796void QQmlComponent::loadUrl(
const QUrl &url, QQmlComponent::CompilationMode mode)
799 d->loadUrl(url, mode);
802void QQmlComponentPrivate::loadUrl(
const QUrl &newUrl, QQmlComponent::CompilationMode mode)
807 if (newUrl.isRelative()) {
809 m_url = m_engine->baseUrl().resolved(QUrl(newUrl.toString()));
810 }
else if (m_engine->baseUrl().isLocalFile() && newUrl.isLocalFile() && !QDir::isAbsolutePath(newUrl.toLocalFile())) {
814 QUrl fixedUrl(newUrl);
815 fixedUrl.setScheme(QString());
818 m_url = m_engine->baseUrl().resolved(fixedUrl);
823 if (m_url.scheme() ==
"qrc"_L1 && !m_url.path().startsWith(
"/"_L1)) {
824 qWarning().nospace().noquote()
825 <<
"QQmlComponent: attempted to load via a relative URL '" << m_url.toString()
826 <<
"' in resource file system. This is not fully supported and may not work";
829 if (newUrl.isEmpty()) {
831 error.setDescription(QQmlComponent::tr(
"Invalid empty URL"));
832 m_state.errors.emplaceBack(error);
838 QQmlTypeLoader::Mode loaderMode = (mode == QQmlComponent::Asynchronous)
839 ? QQmlTypeLoader::Asynchronous
840 : QQmlTypeLoader::PreferSynchronous;
841 QQmlRefPointer<QQmlTypeData> data = QQmlTypeLoader::get(m_engine)->getType(m_url, loaderMode);
843 if (data->isCompleteOrError()) {
848 m_typeData->registerCallback(
this);
849 setProgress(data->progress());
852 emit q->statusChanged(q->status());
856
857
858
859QList<QQmlError> QQmlComponent::errors()
const
861 Q_D(
const QQmlComponent);
862 QList<QQmlError> errors;
863 errors.reserve(d->m_state.errors.size());
864 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors)
865 errors.emplaceBack(annotated.error);
870
871
872
873
874
875
876
877
878
881
882
883
884QString QQmlComponent::errorString()
const
886 Q_D(
const QQmlComponent);
890 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors) {
891 const QQmlError &e = annotated.error;
892 ret += e.url().toString() + QLatin1Char(
':') +
893 QString::number(e.line()) + QLatin1Char(
' ') +
894 e.description() + QLatin1Char(
'\n');
900
901
902
905
906
907
908
909QUrl QQmlComponent::url()
const
911 Q_D(
const QQmlComponent);
916
917
918QQmlComponent::QQmlComponent(QQmlComponentPrivate &dd, QObject *parent)
919 : QObject(dd, parent)
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939QObject *QQmlComponent::create(QQmlContext *context)
942 return d->createWithProperties(
943 nullptr, QVariantMap {}, context, QQmlComponentPrivate::CreateBehavior::Cpp);
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966QObject *QQmlComponent::createWithInitialProperties(
967 const QVariantMap& initialProperties, QQmlContext *context)
970 return d->createWithProperties(
971 nullptr, initialProperties, context, QQmlComponentPrivate::CreateBehavior::Cpp);
977
978QObject *QQmlComponentPrivate::createWithProperties(
979 QObject *parent,
const QVariantMap &properties,
980 QQmlContext *context, CreateBehavior behavior)
984 QObject *rv = doBeginCreate(q, context);
986 if (m_state.isCompletePending()) {
990 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
991 complete(ep, &m_state);
997 QQmlComponent_setQmlParent(rv, parent);
999 if (behavior == CreateBehavior::Qml) {
1001 for (
auto it = properties.cbegin(), end = properties.cend(); it != end; ++it)
1002 ok = setInitialProperty(rv, it.key(), it.value()) && ok;
1003 q->completeCreate();
1004 if (m_state.hasUnsetRequiredProperties()) {
1005 for (
const auto &unsetRequiredProperty : std::as_const(*m_state.requiredProperties())) {
1006 const QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1007 qmlWarning(rv, error);
1009 delete std::exchange(rv,
nullptr);
1012 delete std::exchange(rv,
nullptr);
1015 setInitialProperties(rv, properties);
1016 q->completeCreate();
1017 if (m_state.hasUnsetRequiredProperties())
1018 delete std::exchange(rv,
nullptr);
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
1059
1060
1061QObject *QQmlComponent::beginCreate(QQmlContext *context)
1065 return d->beginCreate(QQmlContextData::get(context));
1070 const int parserStatusCast = type.parserStatusCast();
1071 return parserStatusCast == -1
1073 :
reinterpret_cast<QQmlParserStatus *>(
reinterpret_cast<
char *>(rv) + parserStatusCast);
1076QObject *QQmlComponentPrivate::beginCreate(QQmlRefPointer<QQmlContextData> context)
1079 auto cleanup = qScopeGuard([
this] {
1080 if (!m_state.errors.isEmpty() && lcQmlComponentGeneral().isDebugEnabled()) {
1081 for (
const auto &e : std::as_const(m_state.errors)) {
1082 qCDebug(lcQmlComponentGeneral) <<
"QQmlComponent: " << e.error.toString();
1087 qWarning(
"QQmlComponent: Cannot create a component in a null context");
1091 if (!context->isValid()) {
1092 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1096 if (context->engine() != m_engine) {
1097 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1101 if (m_state.isCompletePending()) {
1102 qWarning(
"QQmlComponent: Cannot create new component instance before completing the previous");
1108 m_state.errors.removeIf([](
const auto &e) {
return e.isTransient; });
1109 m_state.clearRequiredProperties();
1111 if (!q->isReady()) {
1112 qWarning(
"QQmlComponent: Component is not ready");
1117 static const int maxCreationDepth = 10;
1118 if (creationDepth >= maxCreationDepth) {
1119 qWarning(
"QQmlComponent: Component creation is recursing - aborting");
1123 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(m_engine);
1125 enginePriv->inProgressCreations++;
1126 m_state.errors.clear();
1127 m_state.setCompletePending(
true);
1129 QObject *rv =
nullptr;
1131 const QQmlType type = loadedType();
1132 if (!type.isValid()) {
1133 enginePriv->referenceScarceResources();
1134 const QString *icName = m_inlineComponentName.get();
1135 m_state.initCreator(
1136 context, m_compilationUnit, m_creationContext, icName ? *icName : QString());
1138 QQmlObjectCreator::CreationFlags flags;
1140 flags = QQmlObjectCreator::InlineComponent;
1142 m_start = m_compilationUnit->inlineComponentId(*icName);
1143 Q_ASSERT(m_start > 0);
1145 flags = QQmlObjectCreator::NormalObject;
1148 rv = m_state.creator()->create(m_start,
nullptr,
nullptr, flags);
1150 m_state.appendCreatorErrors();
1151 enginePriv->dereferenceScarceResources();
1154 rv = type.createWithQQmlData();
1155 QQmlPropertyCache::ConstPtr propertyCache = QQmlData::ensurePropertyCache(rv);
1156 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv)) {
1157 parserStatus->classBegin();
1158 m_state.ensureRequiredPropertyStorage(rv);
1159 }
else if (type.finalizerCast() != -1) {
1160 m_state.ensureRequiredPropertyStorage(rv);
1163 if (propertyCache) {
1164 for (
int i = 0, propertyCount = propertyCache->propertyCount(); i < propertyCount; ++i) {
1165 if (
const QQmlPropertyData *propertyData = propertyCache->property(i); propertyData->isRequired()) {
1166 m_state.ensureRequiredPropertyStorage(rv);
1167 RequiredPropertyInfo info;
1168 info.propertyName = propertyData->name(rv);
1169 m_state.addPendingRequiredProperty(rv, propertyData, info);
1180 QQmlData *ddata = QQmlData::get(rv);
1184 ddata->indestructible =
true;
1185 ddata->explicitIndestructibleSet =
true;
1186 ddata->rootObjectInCreation =
false;
1189 if (!ddata->outerContext)
1190 ddata->outerContext = context.data();
1191 if (!ddata->context)
1192 ddata->context = context.data();
1198void QQmlComponentPrivate::beginDeferred(QQmlEnginePrivate *enginePriv,
1199 QObject *object, DeferredState *deferredState)
1201 QQmlData *ddata = QQmlData::get(object);
1202 Q_ASSERT(!ddata->deferredData.isEmpty());
1204 deferredState->reserve(ddata->deferredData.size());
1206 for (QQmlData::DeferredData *deferredData : std::as_const(ddata->deferredData)) {
1207 enginePriv->inProgressCreations++;
1209 ConstructionState state;
1210 state.setCompletePending(
true);
1212 auto creator = state.initCreator(
1213 deferredData->context->parent(),
1214 deferredData->compilationUnit,
1215 QQmlRefPointer<QQmlContextData>(),
1216 deferredData->inlineComponentName
1219 if (!creator->populateDeferredProperties(object, deferredData))
1220 state.appendCreatorErrors();
1221 deferredData->bindings.clear();
1223 deferredState->push_back(std::move(state));
1227void QQmlComponentPrivate::completeDeferred(QQmlEnginePrivate *enginePriv, QQmlComponentPrivate::DeferredState *deferredState)
1229 for (ConstructionState &state : *deferredState)
1230 complete(enginePriv, &state);
1233void QQmlComponentPrivate::complete(QQmlEnginePrivate *enginePriv, ConstructionState *state)
1235 if (state->isCompletePending()) {
1236 QQmlInstantiationInterrupt interrupt;
1237 state->creator()->finalize(interrupt);
1239 state->setCompletePending(
false);
1241 enginePriv->inProgressCreations--;
1243 if (0 == enginePriv->inProgressCreations) {
1244 while (enginePriv->erroredBindings) {
1245 enginePriv->warning(enginePriv->erroredBindings->removeError());
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268QQmlProperty QQmlComponentPrivate::removePropertyFromRequired(
1269 QObject *createdComponent,
const QString &name,
1270 RequiredProperties *requiredProperties, QQmlEngine *engine,
1271 bool *wasInRequiredProperties)
1273 Q_ASSERT(requiredProperties);
1274 QQmlProperty prop(createdComponent, name, engine);
1275 auto privProp = QQmlPropertyPrivate::get(prop);
1276 if (prop.isValid()) {
1278 const QQmlPropertyData *targetProp = &privProp->core;
1279 if (targetProp->isAlias()) {
1280 auto target = createdComponent;
1281 QQmlPropertyIndex originalIndex(targetProp->coreIndex());
1282 QQmlPropertyIndex propIndex;
1283 QQmlPropertyPrivate::findAliasTarget(target, originalIndex, &target, &propIndex);
1284 QQmlData *data = QQmlData::get(target);
1285 Q_ASSERT(data && data->propertyCache);
1286 targetProp = data->propertyCache->property(propIndex.coreIndex());
1290 QQmlData *data = QQmlData::get(createdComponent);
1291 Q_ASSERT(data && data->propertyCache);
1292 targetProp = data->propertyCache->property(targetProp->coreIndex());
1294 auto it = requiredProperties->constFind({createdComponent, targetProp});
1295 if (it != requiredProperties->cend()) {
1296 if (wasInRequiredProperties)
1297 *wasInRequiredProperties =
true;
1298 requiredProperties->erase(it);
1300 if (wasInRequiredProperties)
1301 *wasInRequiredProperties =
false;
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317void QQmlComponent::completeCreate()
1321 d->completeCreate();
1324void QQmlComponentPrivate::completeCreate()
1326 if (m_state.hasUnsetRequiredProperties()) {
1327 for (
const auto& unsetRequiredProperty: std::as_const(*m_state.requiredProperties())) {
1328 QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1329 m_state.errors.push_back(QQmlComponentPrivate::AnnotatedQmlError { error,
true });
1333 const QQmlType type = loadedType();
1334 if (type.isValid()) {
1335 QObject *rv = m_state.target();
1336 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv))
1337 parserStatus->componentComplete();
1339 if (
const int finalizerCast = type.finalizerCast(); finalizerCast != -1) {
1340 auto *hook =
reinterpret_cast<QQmlFinalizerHook *>(
1341 reinterpret_cast<
char *>(rv) + finalizerCast);
1342 hook->componentFinalized();
1346
1347
1348
1349
1350 m_state.setCompletePending(
false);
1351 QQmlEnginePrivate::get(m_engine)->inProgressCreations--;
1352 }
else if (m_state.isCompletePending()) {
1354 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
1355 complete(ep, &m_state);
1360QQmlComponentAttached::QQmlComponentAttached(QObject *parent)
1361: QObject(parent), m_prev(
nullptr), m_next(
nullptr)
1365QQmlComponentAttached::~QQmlComponentAttached()
1367 if (m_prev) *m_prev = m_next;
1368 if (m_next) m_next->m_prev = m_prev;
1374
1375
1376QQmlComponentAttached *QQmlComponent::qmlAttachedProperties(QObject *obj)
1378 QQmlComponentAttached *a =
new QQmlComponentAttached(obj);
1380 QQmlEngine *engine = qmlEngine(obj);
1384 QQmlEnginePrivate *p = QQmlEnginePrivate::get(engine);
1385 if (p->activeObjectCreator) {
1386 a->insertIntoList(p->activeObjectCreator->componentAttachment());
1388 QQmlData *d = QQmlData::get(obj);
1390 Q_ASSERT(d->context);
1391 d->context->addComponentAttached(a);
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414void QQmlComponent::loadFromModule(QAnyStringView uri, QAnyStringView typeName,
1415 QQmlComponent::CompilationMode mode)
1419 QQmlTypeLoader::Mode typeLoaderMode = QQmlTypeLoader::Synchronous;
1421 case QQmlComponent::PreferSynchronous:
1422 typeLoaderMode = QQmlTypeLoader::PreferSynchronous;
1424 case QQmlComponent::Asynchronous:
1425 typeLoaderMode = QQmlTypeLoader::Asynchronous;
1429 d->prepareLoadFromModule(uri, typeName, typeLoaderMode);
1430 if (d->m_loadHelper->isCompleteOrError())
1431 d->completeLoadFromModule(uri, typeName);
1433 d->m_loadHelper->registerCallback(d);
1436void QQmlComponentPrivate::prepareLoadFromModule(
1437 QAnyStringView uri, QAnyStringView typeName, QQmlTypeLoader::Mode mode)
1441 m_loadHelper->unregisterCallback(
this);
1444 m_loadHelper = QQml::makeRefPointer<LoadHelper>(QQmlTypeLoader::get(m_engine), uri, typeName, mode);
1447void QQmlComponentPrivate::completeLoadFromModule(QAnyStringView uri, QAnyStringView typeName)
1452 auto reportError = [&](QString msg) {
1454 error.setDescription(msg);
1455 m_state.errors.push_back(std::move(error));
1457 emit q->statusChanged(q->Error);
1459 auto emitComplete = [&]() {
1461 emit q->statusChanged(q->status());
1466 const QQmlType type = m_loadHelper->type();
1468 if (m_loadHelper->resolveTypeResult() == LoadHelper::ResolveTypeResult::NoSuchModule) {
1469 reportError(QLatin1String(R"(No module named "%1" found)").arg(uri.toString()));
1470 }
else if (!type.isValid()) {
1471 reportError(QLatin1String(R"(Module "%1" contains no type named "%2")")
1472 .arg(uri.toString(), typeName.toString()));
1473 }
else if (type.isCreatable()) {
1475 }
else if (type.isComposite()) {
1476 QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous;
1477 switch (m_loadHelper->mode()) {
1478 case QQmlTypeLoader::Asynchronous:
1479 mode = QQmlComponent::Asynchronous;
1481 case QQmlTypeLoader::PreferSynchronous:
1482 case QQmlTypeLoader::Synchronous:
1483 mode = QQmlComponent::PreferSynchronous;
1488 loadUrl(type.sourceUrl(), mode);
1489 }
else if (type.isInlineComponentType()) {
1490 auto baseUrl = type.sourceUrl();
1491 baseUrl.setFragment(QString());
1493 Q_ASSERT(m_progress == 0.0);
1497 QSignalBlocker blockSignals(q);
1499 loadUrl(baseUrl, QQmlComponent::PreferSynchronous);
1502 if (m_progress != 0.0)
1503 emit q->progressChanged(m_progress);
1509 QString elementName = type.elementName();
1510 if (m_compilationUnit->inlineComponentId(elementName) == -1) {
1511 QString realTypeName = typeName.toString();
1512 realTypeName.truncate(realTypeName.indexOf(u'.'));
1513 QString errorMessage = R"(Type "%1" from module "%2" contains no inline component named "%3".)"_L1.arg(
1514 realTypeName, uri.toString(), elementName);
1515 if (elementName == u"qml")
1516 errorMessage +=
" To load the type \"%1\", drop the \".qml\" extension."_L1.arg(realTypeName);
1517 reportError(std::move(errorMessage));
1519 m_inlineComponentName = std::make_unique<QString>(std::move(elementName));
1522 }
else if (type.isSingleton() || type.isCompositeSingleton()) {
1523 reportError(QLatin1String(R"(%1 is a singleton, and cannot be loaded)").arg(typeName.toString()));
1525 reportError(QLatin1String(
"Could not load %1, as the type is uncreatable").arg(typeName.toString()));
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1549void QQmlComponent::create(QQmlIncubator &incubator, QQmlContext *context, QQmlContext *forContext)
1554 context = d->m_engine->rootContext();
1556 QQmlRefPointer<QQmlContextData> contextData = QQmlContextData::get(context);
1557 QQmlRefPointer<QQmlContextData> forContextData =
1558 forContext ? QQmlContextData::get(forContext) : contextData;
1560 if (!contextData->isValid()) {
1561 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1565 if (contextData->engine() != d->m_engine) {
1566 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1571 qWarning(
"QQmlComponent: Component is not ready");
1576 QExplicitlySharedDataPointer<QQmlIncubatorPrivate> p(incubator.d);
1578 if (d->loadedType().isValid()) {
1582 p->incubateCppBasedComponent(
this, context);
1586 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(d->m_engine);
1588 p->compilationUnit = d->m_compilationUnit;
1589 p->enginePriv = enginePriv;
1590 p->creator.reset(
new QQmlObjectCreator(
1591 contextData, d->m_compilationUnit, d->m_creationContext,
1592 d->m_inlineComponentName ? *d->m_inlineComponentName : QString(), p.data()));
1593 p->subComponentToCreate = d->m_start;
1595 enginePriv->incubate(incubator, forContextData);
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621void QQmlComponent::setInitialProperties(QObject *object,
const QVariantMap &properties)
1624 d->setInitialProperties(object, properties);
1627bool QQmlComponentPrivate::setInitialProperties(QObject *object,
const QVariantMap &properties)
1630 for (
auto it = properties.constBegin(); it != properties.constEnd(); ++it) {
1631 if (it.key().contains(u'.')) {
1632 auto segments = it.key().split(u'.');
1633 QString description = u"Setting initial properties failed: Cannot initialize nested "_s
1635 if (segments.size() >= 2) {
1636 QString s = u" To set %1.%2 as an initial property, create %1, set its "_s
1637 u"property %2, and pass %1 as an initial property."_s;
1638 description += s.arg(segments[0], segments[1]);
1641 error.setUrl(m_url);
1642 error.setDescription(description);
1643 qmlWarning(object, error);
1648 result = setInitialProperty(object, it.key(), it.value()) && result;
1654
1655
1656
1657
1658
1659
1660void QQmlComponentPrivate::incubateObject(
1661 QQmlIncubator *incubationTask,
1662 QQmlComponent *component,
1664 const QQmlRefPointer<QQmlContextData> &context,
1665 const QQmlRefPointer<QQmlContextData> &forContext)
1667 QQmlIncubatorPrivate *incubatorPriv = QQmlIncubatorPrivate::get(incubationTask);
1668 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(engine);
1669 QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component);
1671 incubatorPriv->compilationUnit = componentPriv->m_compilationUnit;
1672 incubatorPriv->enginePriv = enginePriv;
1673 incubatorPriv->creator.reset(
new QQmlObjectCreator(
1674 context, componentPriv->m_compilationUnit, componentPriv->m_creationContext,
1675 m_inlineComponentName ? *m_inlineComponentName : QString()));
1677 if (m_start == -1) {
1678 if (
const QString *icName = componentPriv->m_inlineComponentName.get()) {
1679 m_start = m_compilationUnit->inlineComponentId(*icName);
1680 Q_ASSERT(m_start > 0);
1683 incubatorPriv->subComponentToCreate = componentPriv->m_start;
1685 enginePriv->incubate(*incubationTask, forContext);
1696#define QmlIncubatorObjectMembers(class, Member)
1697 Member(class, HeapValue, HeapValue, valuemapOrObject)
1698 Member(class, HeapValue, HeapValue, statusChanged)
1699 Member(class, Pointer, QmlContext *, qmlContext)
1700 Member(class, NoMark, QQmlComponentIncubator *, incubator)
1701 Member(class, NoMark, QV4QPointer<QObject>, parent)
1704 DECLARE_MARKOBJECTS(QmlIncubatorObject)
1706 void init(QQmlIncubator::IncubationMode = QQmlIncubator::Asynchronous);
1707 inline void destroy();
1737 incubatorObject.set(inc->internalClass->engine, inc);
1741 QV4::Scope scope(incubatorObject.engine());
1742 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1743 i->statusChanged(s);
1747 QV4::Scope scope(incubatorObject.engine());
1748 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1749 auto d = QQmlIncubatorPrivate::get(
this);
1750 i->setInitialState(o, d->requiredProperties());
1760 me->setParent(parent);
1761 typedef QQmlPrivate::AutoParentFunction APF;
1762 QList<APF> functions = QQmlMetaType::parentFunctions();
1764 bool needParent =
false;
1765 for (
int ii = 0; ii < functions.size(); ++ii) {
1766 QQmlPrivate::AutoParentResult res = functions.at(ii)(me, parent);
1767 if (res == QQmlPrivate::Parented) {
1770 }
else if (res == QQmlPrivate::IncompatibleParent) {
1775 qmlWarning(me) <<
"Created graphical object was not placed in the graphics scene.";
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
1818
1819
1822void QQmlComponentPrivate::setInitialProperties(
1823 QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext,
const QV4::Value &o,
1824 const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent,
1825 const QQmlObjectCreator *creator)
1827 QV4::Scope scope(engine);
1828 QV4::ScopedObject object(scope);
1829 QV4::ScopedObject valueMap(scope, v);
1830 QV4::ObjectIterator it(scope, valueMap, QV4::ObjectIterator::EnumerableOnly);
1831 QV4::ScopedString name(scope);
1832 QV4::ScopedValue val(scope);
1833 if (engine->hasException)
1837 QV4::ScopedStackFrame frame(scope, qmlContext ? qmlContext : engine->scriptContext());
1840 name = it.nextPropertyNameAsString(val);
1844 const QStringList properties = name->toQString().split(QLatin1Char(
'.'));
1845 bool isTopLevelProperty = properties.size() == 1;
1846 for (
int i = 0; i < properties.size() - 1; ++i) {
1847 name = engine->newString(properties.at(i));
1848 object = object->get(name);
1849 if (engine->hasException || !object) {
1853 if (engine->hasException) {
1854 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1859 error.setUrl(qmlContext ? qmlContext->qmlContext()->url() : QUrl());
1860 error.setDescription(QLatin1String(
"Cannot resolve property \"%1\".")
1861 .arg(properties.join(u'.')));
1862 qmlWarning(createdComponent, error);
1865 const QString lastProperty = properties.last();
1866 name = engine->newString(lastProperty);
1867 object->put(name, val);
1868 if (engine->hasException) {
1869 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1871 }
else if (isTopLevelProperty && requiredProperties) {
1872 auto prop = removePropertyFromRequired(createdComponent, name->toQString(),
1873 requiredProperties, engine->qmlEngine());
1876 removePendingQPropertyBinding(object, lastProperty, creator);
1879 engine->hasException =
false;
1882QQmlError QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(
const RequiredPropertyInfo &unsetRequiredProperty)
1885 QString description = QLatin1String(
"Required property %1 was not initialized").arg(unsetRequiredProperty.propertyName);
1886 switch (unsetRequiredProperty.aliasesToRequired.size()) {
1890 const auto info = unsetRequiredProperty.aliasesToRequired.first();
1891 description += QLatin1String(
"\nIt can be set via the alias property %1 from %2\n").arg(info.propertyName, info.fileUrl.toString());
1895 description += QLatin1String(
"\nIt can be set via one of the following alias properties:");
1896 for (
auto aliasInfo: unsetRequiredProperty.aliasesToRequired) {
1897 description += QLatin1String(
"\n- %1 (%2)").arg(aliasInfo.propertyName, aliasInfo.fileUrl.toString());
1899 description += QLatin1Char(
'\n');
1901 error.setDescription(description);
1902 error.setUrl(unsetRequiredProperty.fileUrl);
1903 error.setLine(qmlConvertSourceCoordinate<quint32,
int>(
1904 unsetRequiredProperty.location.line()));
1905 error.setColumn(qmlConvertSourceCoordinate<quint32,
int>(
1906 unsetRequiredProperty.location.column()));
1910#if QT_DEPRECATED_SINCE(6
, 3
)
1912
1913
1914void QQmlComponent::createObject(QQmlV4FunctionPtr args)
1917 Q_ASSERT(d->m_engine);
1920 qmlWarning(
this) <<
"Unsuitable arguments passed to createObject(). The first argument should "
1921 "be a QObject* or null, and the second argument should be a JavaScript "
1922 "object or a QVariantMap";
1924 QObject *parent =
nullptr;
1925 QV4::ExecutionEngine *v4 = args->v4engine();
1926 QV4::Scope scope(v4);
1927 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
1929 if (args->length() >= 1) {
1930 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
1932 parent = qobjectWrapper->object();
1935 if (args->length() >= 2) {
1936 QV4::ScopedValue v(scope, (*args)[1]);
1937 if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
1938 qmlWarning(
this) << tr(
"createObject: value is not an object");
1939 args->setReturnValue(QV4::Encode::null());
1945 QQmlContext *ctxt = creationContext();
1946 if (!ctxt) ctxt = d->m_engine->rootContext();
1948 QObject *rv = beginCreate(ctxt);
1951 args->setReturnValue(QV4::Encode::null());
1955 QQmlComponent_setQmlParent(rv, parent);
1957 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4, rv));
1958 Q_ASSERT(object->isObject());
1960 if (!valuemap->isUndefined()) {
1961 QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->qmlContext());
1962 QQmlComponentPrivate::setInitialProperties(
1963 v4, qmlContext, object, valuemap, d->m_state.requiredProperties(), rv,
1964 d->m_state.creator());
1966 if (d->m_state.hasUnsetRequiredProperties()) {
1967 QList<QQmlError> errors;
1968 for (
const auto &requiredProperty: std::as_const(*d->m_state.requiredProperties())) {
1969 errors.push_back(QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(requiredProperty));
1971 qmlWarning(rv, errors);
1972 args->setReturnValue(QV4::Encode::null());
1977 d->completeCreate();
1979 Q_ASSERT(QQmlData::get(rv));
1980 QQmlData::get(rv)->explicitIndestructibleSet =
false;
1981 QQmlData::get(rv)->indestructible =
false;
1983 args->setReturnValue(object->asReturnedValue());
1988
1989
1990QObject *QQmlComponent::createObject(QObject *parent,
const QVariantMap &properties)
1993 Q_ASSERT(d->m_engine);
1994 QObject *rv = d->createWithProperties(
1995 parent, properties, creationContext(), QQmlComponentPrivate::CreateBehavior::Qml);
1997 QQmlData *qmlData = QQmlData::get(rv);
1999 qmlData->explicitIndestructibleSet =
false;
2000 qmlData->indestructible =
false;
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
2057
2058
2061
2062
2063void QQmlComponent::incubateObject(QQmlV4FunctionPtr args)
2066 Q_ASSERT(d->m_engine);
2069 QV4::ExecutionEngine *v4 = args->v4engine();
2070 QV4::Scope scope(v4);
2072 QObject *parent =
nullptr;
2073 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
2074 QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous;
2076 if (args->length() >= 1) {
2077 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
2079 parent = qobjectWrapper->object();
2082 if (args->length() >= 2) {
2083 QV4::ScopedValue v(scope, (*args)[1]);
2085 }
else if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
2086 qmlWarning(
this) << tr(
"createObject: value is not an object");
2087 args->setReturnValue(QV4::Encode::null());
2094 if (args->length() >= 3) {
2095 QV4::ScopedValue val(scope, (*args)[2]);
2096 quint32 v = val->toUInt32();
2098 mode = QQmlIncubator::Asynchronous;
2100 mode = QQmlIncubator::AsynchronousIfNested;
2103 QQmlComponentExtension *e = componentExtension(args->v4engine());
2105 QV4::Scoped<QV4::QmlIncubatorObject> r(scope, v4->memoryManager->allocate<QV4::QmlIncubatorObject>(mode));
2106 QV4::ScopedObject p(scope, e->incubationProto.value());
2107 r->setPrototypeOf(p);
2109 if (!valuemap->isUndefined())
2110 r->d()->valuemapOrObject.set(scope.engine, valuemap);
2111 r->d()->qmlContext.set(scope.engine, v4->qmlContext());
2112 r->d()->parent = parent;
2114 QQmlIncubator *incubator = r->d()->incubator;
2115 create(*incubator, creationContext());
2117 if (incubator->status() == QQmlIncubator::Null) {
2118 args->setReturnValue(QV4::Encode::null());
2120 args->setReturnValue(r.asReturnedValue());
2125void QQmlComponentPrivate::initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext,
const QV4::Value &valuemap, QObject *toCreate, RequiredProperties *requiredProperties)
2127 QV4::ExecutionEngine *v4engine = m_engine->handle();
2128 QV4::Scope scope(v4engine);
2130 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate));
2131 Q_ASSERT(object->as<QV4::Object>());
2133 if (!valuemap.isUndefined()) {
2134 setInitialProperties(
2135 v4engine, qmlContext, object, valuemap, requiredProperties, toCreate, m_state.creator());
2139QQmlComponentExtension::QQmlComponentExtension(QV4::ExecutionEngine *v4)
2141 QV4::Scope scope(v4);
2142 QV4::ScopedObject proto(scope, v4->newObject());
2143 proto->defineAccessorProperty(QStringLiteral(
"onStatusChanged"),
2144 QV4::QmlIncubatorObject::method_get_statusChanged, QV4::QmlIncubatorObject::method_set_statusChanged);
2145 proto->defineAccessorProperty(QStringLiteral(
"status"), QV4::QmlIncubatorObject::method_get_status,
nullptr);
2146 proto->defineAccessorProperty(QStringLiteral(
"object"), QV4::QmlIncubatorObject::method_get_object,
nullptr);
2147 proto->defineDefaultProperty(QStringLiteral(
"forceCompletion"), QV4::QmlIncubatorObject::method_forceCompletion);
2149 incubationProto.set(v4, proto);
2152QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_object(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2154 QV4::Scope scope(b);
2155 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2159 return QV4::QObjectWrapper::wrap(scope.engine, o->d()->incubator->object());
2162QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_forceCompletion(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2164 QV4::Scope scope(b);
2165 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2169 o->d()->incubator->forceCompletion();
2174QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_status(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2176 QV4::Scope scope(b);
2177 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2181 return QV4::Encode(o->d()->incubator->status());
2184QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2186 QV4::Scope scope(b);
2187 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2191 return QV4::Encode(o->d()->statusChanged);
2194QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_set_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *argv,
int argc)
2196 QV4::Scope scope(b);
2197 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2201 o->d()->statusChanged.set(scope.engine, argv[0]);
2206QQmlComponentExtension::~QQmlComponentExtension()
2210void QV4::Heap::QmlIncubatorObject::init(QQmlIncubator::IncubationMode m)
2213 valuemapOrObject.set(internalClass->engine, QV4::Value::undefinedValue());
2214 statusChanged.set(internalClass->engine, QV4::Value::undefinedValue());
2216 qmlContext.set(internalClass->engine,
nullptr);
2217 incubator =
new QQmlComponentIncubator(
this, m);
2220void QV4::Heap::QmlIncubatorObject::destroy() {
2228 QQmlComponent_setQmlParent(o, d()->parent);
2230 if (!d()->valuemapOrObject.isUndefined()) {
2231 QV4::ExecutionEngine *v4 = engine();
2232 QV4::Scope scope(v4);
2233 QV4::ScopedObject obj(scope, QV4::QObjectWrapper::wrap(v4, o));
2234 QV4::Scoped<QV4::QmlContext> qmlCtxt(scope, d()->qmlContext);
2235 QQmlComponentPrivate::setInitialProperties(
2236 v4, qmlCtxt, obj, d()->valuemapOrObject, requiredProperties, o,
2237 QQmlIncubatorPrivate::get(d()->incubator)->creator.data());
2243 QV4::Scope scope(engine());
2245 QObject *object = d()->incubator->object();
2247 if (s == QQmlIncubator::Ready) {
2250 d()->valuemapOrObject.set(scope.engine, QV4::QObjectWrapper::wrap(scope.engine, object));
2252 QQmlData *ddata = QQmlData::get(object);
2254 ddata->explicitIndestructibleSet =
false;
2255 ddata->indestructible =
false;
2258 QV4::ScopedFunctionObject f(scope, d()->statusChanged);
2260 QV4::JSCallArguments jsCallData(scope, 1);
2261 *jsCallData.thisObject =
this;
2262 jsCallData.args[0] = QV4::Value::fromUInt32(s);
2263 f->call(jsCallData);
2264 if (scope.hasException()) {
2265 QQmlError error = scope.engine->catchExceptionAsQmlError();
2266 QQmlEnginePrivate::warning(QQmlEnginePrivate::get(scope.engine->qmlEngine()), error);
2270 if (s != QQmlIncubator::Loading)
2271 d()->incubator->incubatorObject.clear();
2274#undef INITIALPROPERTIES_SOURCE
2278#include "moc_qqmlcomponent.cpp"
2279#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)