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();
721void QQmlComponentPrivate::setData(
const QByteArray &data,
const QUrl &url, QQmlComponent::CompilationMode compilationMode)
725 qWarning(
"QQmlComponent: Must provide an engine before calling setData");
736 m_engine->handle()->trimCompilationUnitsForUrl(url);
738 QQmlTypeLoader::Mode mode = compilationMode == QQmlComponent::Asynchronous
739 ? QQmlTypeLoader::Asynchronous
740 : QQmlTypeLoader::PreferSynchronous;
741 QQmlRefPointer<QQmlTypeData> typeData = QQmlTypeLoader::get(m_engine)->getType(data, url, mode);
743 if (typeData->isCompleteOrError()) {
744 fromTypeData(typeData);
747 m_typeData = typeData;
748 m_typeData->registerCallback(
this);
749 setProgress(typeData->progress());
754
755
756
757
758
759
760
761
762
763
764void QQmlComponent::setData(
const QByteArray &data,
const QUrl &url)
767 d->setData(data, url, PreferSynchronous);
768 emit statusChanged(status());
772
773
774
775
776
777
778
779
780
781
782
783
784void QQmlComponent::setDataAsynchronous(
const QByteArray &data,
const QUrl &baseUrl)
787 d->setData(data, baseUrl, Asynchronous);
788 emit statusChanged(status());
792
793
794
795QQmlContext *QQmlComponent::creationContext()
const
797 Q_D(
const QQmlComponent);
798 if (!d->m_creationContext.isNull())
799 return d->m_creationContext->asQQmlContext();
801 return qmlContext(
this);
805
806
807
808
809QQmlEngine *QQmlComponent::engine()
const
811 Q_D(
const QQmlComponent);
816
817
818
819
820void QQmlComponent::loadUrl(
const QUrl &url)
827
828
829
830
831
832void QQmlComponent::loadUrl(
const QUrl &url, QQmlComponent::CompilationMode mode)
835 d->loadUrl(url, mode);
838void QQmlComponentPrivate::loadUrl(
const QUrl &newUrl, QQmlComponent::CompilationMode mode)
843 if (newUrl.isRelative()) {
845 m_url = m_engine->baseUrl().resolved(QUrl(newUrl.toString()));
846 }
else if (m_engine->baseUrl().isLocalFile() && newUrl.isLocalFile() && !QDir::isAbsolutePath(newUrl.toLocalFile())) {
850 QUrl fixedUrl(newUrl);
851 fixedUrl.setScheme(QString());
854 m_url = m_engine->baseUrl().resolved(fixedUrl);
859 if (m_url.scheme() ==
"qrc"_L1 && !m_url.path().startsWith(
"/"_L1)) {
860 qWarning().nospace().noquote()
861 <<
"QQmlComponent: attempted to load via a relative URL '" << m_url.toString()
862 <<
"' in resource file system. This is not fully supported and may not work";
865 if (newUrl.isEmpty()) {
867 error.setDescription(QQmlComponent::tr(
"Invalid empty URL"));
868 m_state.errors.emplaceBack(error);
874 QQmlTypeLoader::Mode loaderMode = (mode == QQmlComponent::Asynchronous)
875 ? QQmlTypeLoader::Asynchronous
876 : QQmlTypeLoader::PreferSynchronous;
877 QQmlRefPointer<QQmlTypeData> data = QQmlTypeLoader::get(m_engine)->getType(m_url, loaderMode);
879 if (data->isCompleteOrError()) {
884 m_typeData->registerCallback(
this);
885 setProgress(data->progress());
888 emit q->statusChanged(q->status());
892
893
894
895QList<QQmlError> QQmlComponent::errors()
const
897 Q_D(
const QQmlComponent);
898 QList<QQmlError> errors;
899 errors.reserve(d->m_state.errors.size());
900 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors)
901 errors.emplaceBack(annotated.error);
906
907
908
909
910
911
912
913
914
917
918
919
920QString QQmlComponent::errorString()
const
922 Q_D(
const QQmlComponent);
926 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors) {
927 ret += annotated.error.toString() + QLatin1Char(
'\n');
933
934
935
938
939
940
941
942QUrl QQmlComponent::url()
const
944 Q_D(
const QQmlComponent);
949
950
951QQmlComponent::QQmlComponent(QQmlComponentPrivate &dd, QObject *parent)
952 : QObject(dd, parent)
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972QObject *QQmlComponent::create(QQmlContext *context)
975 return d->createWithProperties(
976 nullptr, QVariantMap {}, context, QQmlComponentPrivate::CreateBehavior::Cpp);
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999QObject *QQmlComponent::createWithInitialProperties(
1000 const QVariantMap& initialProperties, QQmlContext *context)
1003 return d->createWithProperties(
1004 nullptr, initialProperties, context, QQmlComponentPrivate::CreateBehavior::Cpp);
1010
1011QObject *QQmlComponentPrivate::createWithProperties(
1012 QObject *parent,
const QVariantMap &properties,
1013 QQmlContext *context, CreateBehavior behavior)
1017 QObject *rv = doBeginCreate(q, context);
1019 if (m_state.isCompletePending()) {
1023 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
1024 complete(ep, &m_state);
1030 QQmlComponent_setQmlParent(rv, parent);
1032 if (behavior == CreateBehavior::Qml) {
1034 for (
auto it = properties.cbegin(), end = properties.cend(); it != end; ++it)
1035 ok = setInitialProperty(rv, it.key(), it.value()) && ok;
1036 q->completeCreate();
1037 if (m_state.hasUnsetRequiredProperties()) {
1038 for (
const auto &unsetRequiredProperty : std::as_const(*m_state.requiredProperties())) {
1039 const QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1040 qmlWarning(rv, error);
1042 delete std::exchange(rv,
nullptr);
1045 delete std::exchange(rv,
nullptr);
1048 setInitialProperties(rv, properties);
1049 q->completeCreate();
1050 if (m_state.hasUnsetRequiredProperties())
1051 delete std::exchange(rv,
nullptr);
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094QObject *QQmlComponent::beginCreate(QQmlContext *context)
1098 return d->beginCreate(QQmlContextData::get(context));
1103 const int parserStatusCast = type.parserStatusCast();
1104 return parserStatusCast == -1
1106 :
reinterpret_cast<QQmlParserStatus *>(
reinterpret_cast<
char *>(rv) + parserStatusCast);
1109QObject *QQmlComponentPrivate::beginCreate(QQmlRefPointer<QQmlContextData> context)
1112 auto cleanup = qScopeGuard([
this] {
1113 if (!m_state.errors.isEmpty() && lcQmlComponentGeneral().isDebugEnabled()) {
1114 for (
const auto &e : std::as_const(m_state.errors)) {
1115 qCDebug(lcQmlComponentGeneral) <<
"QQmlComponent: " << e.error.toString();
1120 qWarning(
"QQmlComponent: Cannot create a component in a null context");
1124 if (!context->isValid()) {
1125 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1129 if (context->engine() != m_engine) {
1130 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1134 if (m_state.isCompletePending()) {
1135 qWarning(
"QQmlComponent: Cannot create new component instance before completing the previous");
1141 m_state.errors.removeIf([](
const auto &e) {
return e.isTransient; });
1142 m_state.clearRequiredProperties();
1144 if (!q->isReady()) {
1145 qWarning(
"QQmlComponent: Component is not ready");
1150 static const int maxCreationDepth = 10;
1151 if (creationDepth >= maxCreationDepth) {
1152 qWarning(
"QQmlComponent: Component creation is recursing - aborting");
1156 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(m_engine);
1158 enginePriv->inProgressCreations++;
1159 m_state.errors.clear();
1160 m_state.setCompletePending(
true);
1162 QObject *rv =
nullptr;
1163 auto setupDData = [&]() {
1164 QQmlData *ddata = QQmlData::get(rv);
1168 ddata->indestructible =
true;
1169 ddata->explicitIndestructibleSet =
true;
1170 ddata->rootObjectInCreation =
false;
1173 if (!ddata->outerContext)
1174 ddata->outerContext = context.data();
1175 if (!ddata->context)
1176 ddata->context = context.data();
1179 const QQmlType type = loadedType();
1180 if (!type.isValid()) {
1181 enginePriv->referenceScarceResources();
1182 const QString *icName = m_inlineComponentName.get();
1183 m_state.initCreator(
1184 context, m_compilationUnit, m_creationContext, icName ? *icName : QString());
1186 QQmlObjectCreator::CreationFlags flags;
1188 flags = QQmlObjectCreator::InlineComponent;
1190 m_start = m_compilationUnit->inlineComponentId(*icName);
1191 Q_ASSERT(m_start > 0);
1193 flags = QQmlObjectCreator::NormalObject;
1196 rv = m_state.creator()->create(m_start,
nullptr,
nullptr, flags);
1198 m_state.appendCreatorErrors();
1201 enginePriv->dereferenceScarceResources();
1204 rv = type.createWithQQmlData();
1205 QQmlPropertyCache::ConstPtr propertyCache = QQmlData::ensurePropertyCache(rv);
1207 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv)) {
1208 parserStatus->classBegin();
1209 m_state.ensureRequiredPropertyStorage(rv);
1210 }
else if (type.finalizerCast() != -1) {
1211 m_state.ensureRequiredPropertyStorage(rv);
1214 if (propertyCache) {
1215 for (
int i = 0, propertyCount = propertyCache->propertyCount(); i < propertyCount; ++i) {
1216 if (
const QQmlPropertyData *propertyData = propertyCache->property(i); propertyData->isRequired()) {
1217 m_state.ensureRequiredPropertyStorage(rv);
1218 RequiredPropertyInfo info;
1219 info.propertyName = propertyData->name(rv);
1220 m_state.addPendingRequiredProperty(rv, propertyData, info);
1233void QQmlComponentPrivate::beginDeferred(QQmlEnginePrivate *enginePriv,
1234 QObject *object, DeferredState *deferredState)
1236 QQmlData *ddata = QQmlData::get(object);
1237 Q_ASSERT(!ddata->deferredData.isEmpty());
1239 deferredState->reserve(ddata->deferredData.size());
1241 for (QQmlData::DeferredData *deferredData : std::as_const(ddata->deferredData)) {
1242 enginePriv->inProgressCreations++;
1244 ConstructionState state;
1245 state.setCompletePending(
true);
1247 auto creator = state.initCreator(
1248 deferredData->context->parent(),
1249 deferredData->compilationUnit,
1250 QQmlRefPointer<QQmlContextData>(),
1251 deferredData->inlineComponentName
1254 if (!creator->populateDeferredProperties(object, deferredData))
1255 state.appendCreatorErrors();
1256 deferredData->bindings.clear();
1258 deferredState->push_back(std::move(state));
1262void QQmlComponentPrivate::completeDeferred(QQmlEnginePrivate *enginePriv, QQmlComponentPrivate::DeferredState *deferredState)
1264 for (ConstructionState &state : *deferredState)
1265 complete(enginePriv, &state);
1268void QQmlComponentPrivate::complete(QQmlEnginePrivate *enginePriv, ConstructionState *state)
1270 if (state->isCompletePending()) {
1271 QQmlInstantiationInterrupt interrupt;
1272 state->creator()->finalize(interrupt);
1274 state->setCompletePending(
false);
1276 enginePriv->inProgressCreations--;
1278 if (0 == enginePriv->inProgressCreations) {
1279 while (enginePriv->erroredBindings) {
1280 enginePriv->warning(enginePriv->erroredBindings->removeError());
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303QQmlProperty QQmlComponentPrivate::removePropertyFromRequired(
1304 QObject *target,
const QString &name, RequiredProperties *requiredProperties,
1305 QQmlEngine *engine,
bool *wasInRequiredProperties)
1307 Q_ASSERT(requiredProperties);
1309 const QQmlProperty prop(target, name, engine);
1310 if (!prop.isValid()) {
1311 if (wasInRequiredProperties)
1312 *wasInRequiredProperties =
false;
1316 const QQmlPropertyPrivate *privProp = QQmlPropertyPrivate::get(prop);
1320 const QQmlPropertyData *targetProp = &privProp->core;
1321 QQmlData *data = QQmlData::get(target);
1322 Q_ASSERT(data && data->propertyCache);
1324 if (targetProp->isAlias()) {
1325 if (requiredProperties->remove(
1326 { target, data->propertyCache->property(targetProp->coreIndex()) })) {
1330 QQmlPropertyIndex originalIndex(targetProp->coreIndex());
1331 QQmlPropertyIndex propIndex;
1332 QQmlPropertyPrivate::findAliasTarget(target, originalIndex, &target, &propIndex);
1333 data = QQmlData::get(target);
1334 Q_ASSERT(data && data->propertyCache);
1335 targetProp = data->propertyCache->property(propIndex.coreIndex());
1339 targetProp = data->propertyCache->property(targetProp->coreIndex());
1343 if (requiredProperties->remove({target, targetProp}))
1346 if (wasInRequiredProperties)
1347 *wasInRequiredProperties = found;
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362void QQmlComponent::completeCreate()
1366 d->completeCreate();
1369void QQmlComponentPrivate::completeCreate()
1371 if (m_state.hasUnsetRequiredProperties()) {
1372 for (
const auto& unsetRequiredProperty: std::as_const(*m_state.requiredProperties())) {
1373 QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1374 m_state.errors.push_back(QQmlComponentPrivate::AnnotatedQmlError { error,
true });
1378 const QQmlType type = loadedType();
1379 if (type.isValid()) {
1380 QObject *rv = m_state.target();
1381 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv))
1382 parserStatus->componentComplete();
1384 if (
const int finalizerCast = type.finalizerCast(); finalizerCast != -1) {
1385 auto *hook =
reinterpret_cast<QQmlFinalizerHook *>(
1386 reinterpret_cast<
char *>(rv) + finalizerCast);
1387 hook->componentFinalized();
1391
1392
1393
1394
1395 m_state.setCompletePending(
false);
1396 QQmlEnginePrivate::get(m_engine)->inProgressCreations--;
1397 }
else if (m_state.isCompletePending()) {
1399 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
1400 complete(ep, &m_state);
1405QQmlComponentAttached::QQmlComponentAttached(QObject *parent)
1406: QObject(parent), m_prev(
nullptr), m_next(
nullptr)
1410QQmlComponentAttached::~QQmlComponentAttached()
1412 if (m_prev) *m_prev = m_next;
1413 if (m_next) m_next->m_prev = m_prev;
1419
1420
1421QQmlComponentAttached *QQmlComponent::qmlAttachedProperties(QObject *obj)
1423 QQmlComponentAttached *a =
new QQmlComponentAttached(obj);
1425 QQmlEngine *engine = qmlEngine(obj);
1429 QQmlEnginePrivate *p = QQmlEnginePrivate::get(engine);
1430 if (p->activeObjectCreator) {
1431 a->insertIntoList(p->activeObjectCreator->componentAttachment());
1433 QQmlData *d = QQmlData::get(obj);
1435 Q_ASSERT(d->context);
1436 d->context->addComponentAttached(a);
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459void QQmlComponent::loadFromModule(QAnyStringView uri, QAnyStringView typeName,
1460 QQmlComponent::CompilationMode mode)
1464 QQmlTypeLoader::Mode typeLoaderMode = QQmlTypeLoader::Synchronous;
1466 case QQmlComponent::PreferSynchronous:
1467 typeLoaderMode = QQmlTypeLoader::PreferSynchronous;
1469 case QQmlComponent::Asynchronous:
1470 typeLoaderMode = QQmlTypeLoader::Asynchronous;
1474 d->prepareLoadFromModule(uri, typeName, typeLoaderMode);
1475 if (d->m_loadHelper->isCompleteOrError())
1476 d->completeLoadFromModule(uri, typeName);
1478 d->m_loadHelper->registerCallback(d);
1481void QQmlComponentPrivate::prepareLoadFromModule(
1482 QAnyStringView uri, QAnyStringView typeName, QQmlTypeLoader::Mode mode)
1486 m_loadHelper->unregisterCallback(
this);
1489 m_loadHelper = QQml::makeRefPointer<LoadHelper>(QQmlTypeLoader::get(m_engine), uri, typeName, mode);
1492void QQmlComponentPrivate::completeLoadFromModule(QAnyStringView uri, QAnyStringView typeName)
1497 auto reportError = [&](QString msg) {
1499 error.setDescription(msg);
1500 m_state.errors.push_back(std::move(error));
1502 emit q->statusChanged(q->Error);
1504 auto emitComplete = [&]() {
1506 emit q->statusChanged(q->status());
1511 const QQmlType type = m_loadHelper->type();
1513 if (m_loadHelper->resolveTypeResult() == LoadHelper::ResolveTypeResult::NoSuchModule) {
1514 reportError(QLatin1String(R"(No module named "%1" found)").arg(uri.toString()));
1515 }
else if (!type.isValid()) {
1516 reportError(QLatin1String(R"(Module "%1" contains no type named "%2")")
1517 .arg(uri.toString(), typeName.toString()));
1518 }
else if (type.isCreatable()) {
1520 }
else if (type.isInlineComponent()) {
1521 auto baseUrl = type.sourceUrl();
1522 baseUrl.setFragment(QString());
1524 Q_ASSERT(m_progress == 0.0);
1528 QSignalBlocker blockSignals(q);
1530 loadUrl(baseUrl, QQmlComponent::PreferSynchronous);
1533 if (m_progress != 0.0)
1534 emit q->progressChanged(m_progress);
1540 QString elementName = type.elementName();
1541 if (m_compilationUnit->inlineComponentId(elementName) == -1) {
1542 QString realTypeName = typeName.toString();
1543 realTypeName.truncate(realTypeName.indexOf(u'.'));
1544 QString errorMessage = R"(Type "%1" from module "%2" contains no inline component named "%3".)"_L1.arg(
1545 realTypeName, uri.toString(), elementName);
1546 if (elementName == u"qml")
1547 errorMessage +=
" To load the type \"%1\", drop the \".qml\" extension."_L1.arg(realTypeName);
1548 reportError(std::move(errorMessage));
1550 m_inlineComponentName = std::make_unique<QString>(std::move(elementName));
1553 }
else if (type.isComposite()) {
1554 QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous;
1555 switch (m_loadHelper->mode()) {
1556 case QQmlTypeLoader::Asynchronous:
1557 mode = QQmlComponent::Asynchronous;
1559 case QQmlTypeLoader::PreferSynchronous:
1560 case QQmlTypeLoader::Synchronous:
1561 mode = QQmlComponent::PreferSynchronous;
1566 loadUrl(type.sourceUrl(), mode);
1567 }
else if (type.isSingleton()) {
1569 reportError(QLatin1String(R"(%1 is a singleton, and cannot be loaded)").arg(typeName.toString()));
1571 reportError(QLatin1String(
"Could not load %1, as the type is uncreatable").arg(typeName.toString()));
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1595void QQmlComponent::create(QQmlIncubator &incubator, QQmlContext *context, QQmlContext *forContext)
1600 context = d->m_engine->rootContext();
1602 QQmlRefPointer<QQmlContextData> contextData = QQmlContextData::get(context);
1603 QQmlRefPointer<QQmlContextData> forContextData =
1604 forContext ? QQmlContextData::get(forContext) : contextData;
1606 if (!contextData->isValid()) {
1607 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1611 if (contextData->engine() != d->m_engine) {
1612 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1617 qWarning(
"QQmlComponent: Component is not ready");
1622 QExplicitlySharedDataPointer<QQmlIncubatorPrivate> p(incubator.d);
1624 if (d->loadedType().isValid()) {
1628 p->incubateCppBasedComponent(
this, context);
1632 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(d->m_engine);
1634 p->compilationUnit = d->m_compilationUnit;
1635 p->enginePriv = enginePriv;
1636 p->creator.reset(
new QQmlObjectCreator(
1637 contextData, d->m_compilationUnit, d->m_creationContext,
1638 d->m_inlineComponentName ? *d->m_inlineComponentName : QString(), p.data()));
1639 p->subComponentToCreate = d->m_start;
1641 enginePriv->incubate(incubator, forContextData);
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667void QQmlComponent::setInitialProperties(QObject *object,
const QVariantMap &properties)
1670 d->setInitialProperties(object, properties);
1673bool QQmlComponentPrivate::setInitialProperties(QObject *object,
const QVariantMap &properties)
1676 for (
auto it = properties.constBegin(); it != properties.constEnd(); ++it) {
1677 if (it.key().contains(u'.')) {
1678 auto segments = it.key().split(u'.');
1679 QString description = u"Setting initial properties failed: Cannot initialize nested "_s
1681 if (segments.size() >= 2) {
1682 QString s = u" To set %1.%2 as an initial property, create %1, set its "_s
1683 u"property %2, and pass %1 as an initial property."_s;
1684 description += s.arg(segments[0], segments[1]);
1687 error.setUrl(m_url);
1688 error.setDescription(description);
1689 qmlWarning(object, error);
1694 result = setInitialProperty(object, it.key(), it.value()) && result;
1700
1701
1702
1703
1704
1705
1706void QQmlComponentPrivate::incubateObject(
1707 QQmlIncubator *incubationTask,
1708 QQmlComponent *component,
1710 const QQmlRefPointer<QQmlContextData> &context,
1711 const QQmlRefPointer<QQmlContextData> &forContext)
1713 QQmlIncubatorPrivate *incubatorPriv = QQmlIncubatorPrivate::get(incubationTask);
1714 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(engine);
1715 QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component);
1717 incubatorPriv->compilationUnit = componentPriv->m_compilationUnit;
1718 incubatorPriv->enginePriv = enginePriv;
1719 incubatorPriv->creator.reset(
new QQmlObjectCreator(
1720 context, componentPriv->m_compilationUnit, componentPriv->m_creationContext,
1721 m_inlineComponentName ? *m_inlineComponentName : QString()));
1723 if (m_start == -1) {
1724 if (
const QString *icName = componentPriv->m_inlineComponentName.get()) {
1725 m_start = m_compilationUnit->inlineComponentId(*icName);
1726 Q_ASSERT(m_start > 0);
1729 incubatorPriv->subComponentToCreate = componentPriv->m_start;
1731 enginePriv->incubate(*incubationTask, forContext);
1742#define QmlIncubatorObjectMembers(class, Member)
1743 Member(class, HeapValue, HeapValue, valuemapOrObject)
1744 Member(class, HeapValue, HeapValue, statusChanged)
1745 Member(class, Pointer, QmlContext *, qmlContext)
1746 Member(class, NoMark, QQmlComponentIncubator *, incubator)
1747 Member(class, NoMark, QV4QPointer<QObject>, parent)
1750 DECLARE_MARKOBJECTS(QmlIncubatorObject)
1752 void init(QQmlIncubator::IncubationMode = QQmlIncubator::Asynchronous);
1753 inline void destroy();
1783 incubatorObject.set(inc->internalClass->engine, inc);
1787 QV4::Scope scope(incubatorObject.engine());
1788 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1789 i->statusChanged(s);
1793 QV4::Scope scope(incubatorObject.engine());
1794 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1795 auto d = QQmlIncubatorPrivate::get(
this);
1796 i->setInitialState(o, d->requiredProperties());
1806 me->setParent(parent);
1807 typedef QQmlPrivate::AutoParentFunction APF;
1808 QList<APF> functions = QQmlMetaType::parentFunctions();
1810 bool needParent =
false;
1811 for (
int ii = 0; ii < functions.size(); ++ii) {
1812 QQmlPrivate::AutoParentResult res = functions.at(ii)(me, parent);
1813 if (res == QQmlPrivate::Parented) {
1816 }
else if (res == QQmlPrivate::IncompatibleParent) {
1821 qmlWarning(me) <<
"Created graphical object was not placed in the graphics scene.";
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1868void QQmlComponentPrivate::setInitialProperties(
1869 QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext,
const QV4::Value &o,
1870 const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent,
1871 const QQmlObjectCreator *creator)
1873 QV4::Scope scope(engine);
1874 QV4::ScopedObject object(scope);
1875 QV4::ScopedObject valueMap(scope, v);
1876 QV4::ObjectIterator it(scope, valueMap, QV4::ObjectIterator::EnumerableOnly);
1877 QV4::ScopedString name(scope);
1878 QV4::ScopedValue val(scope);
1879 if (engine->hasException)
1883 QV4::ScopedStackFrame frame(scope, qmlContext ? qmlContext : engine->scriptContext());
1886 name = it.nextPropertyNameAsString(val);
1890 const QStringList properties = name->toQString().split(QLatin1Char(
'.'));
1891 bool isTopLevelProperty = properties.size() == 1;
1892 for (
int i = 0; i < properties.size() - 1; ++i) {
1893 name = engine->newString(properties.at(i));
1894 object = object->get(name);
1895 if (engine->hasException || !object) {
1899 if (engine->hasException) {
1900 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1905 error.setUrl(qmlContext ? qmlContext->qmlContext()->url() : QUrl());
1906 error.setDescription(QLatin1String(
"Cannot resolve property \"%1\".")
1907 .arg(properties.join(u'.')));
1908 qmlWarning(createdComponent, error);
1911 const QString lastProperty = properties.last();
1912 name = engine->newString(lastProperty);
1913 object->put(name, val);
1914 if (engine->hasException) {
1915 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1917 }
else if (isTopLevelProperty && requiredProperties) {
1918 auto prop = removePropertyFromRequired(createdComponent, name->toQString(),
1919 requiredProperties, engine->qmlEngine());
1922 removePendingQPropertyBinding(object, lastProperty, creator);
1925 engine->hasException =
false;
1928QQmlError QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(
const RequiredPropertyInfo &unsetRequiredProperty)
1931 QString description = QLatin1String(
"Required property %1 was not initialized").arg(unsetRequiredProperty.propertyName);
1932 switch (unsetRequiredProperty.aliasesToRequired.size()) {
1936 const auto info = unsetRequiredProperty.aliasesToRequired.first();
1937 description += QLatin1String(
"\nIt can be set via the alias property %1 from %2\n").arg(info.propertyName, info.fileUrl.toString());
1941 description += QLatin1String(
"\nIt can be set via one of the following alias properties:");
1942 for (
const auto &aliasInfo: unsetRequiredProperty.aliasesToRequired) {
1943 description += QLatin1String(
"\n- %1 (%2)").arg(aliasInfo.propertyName, aliasInfo.fileUrl.toString());
1945 description += QLatin1Char(
'\n');
1947 error.setDescription(description);
1948 error.setUrl(unsetRequiredProperty.fileUrl);
1949 error.setLine(qmlConvertSourceCoordinate<quint32,
int>(
1950 unsetRequiredProperty.location.line()));
1951 error.setColumn(qmlConvertSourceCoordinate<quint32,
int>(
1952 unsetRequiredProperty.location.column()));
1956#if QT_DEPRECATED_SINCE(6
, 3
)
1958
1959
1960void QQmlComponent::createObject(QQmlV4FunctionPtr args)
1963 Q_ASSERT(d->m_engine);
1966 qmlWarning(
this) <<
"Unsuitable arguments passed to createObject(). The first argument should "
1967 "be a QObject* or null, and the second argument should be a JavaScript "
1968 "object or a QVariantMap";
1970 QObject *parent =
nullptr;
1971 QV4::ExecutionEngine *v4 = args->v4engine();
1972 QV4::Scope scope(v4);
1973 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
1975 if (args->length() >= 1) {
1976 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
1978 parent = qobjectWrapper->object();
1981 if (args->length() >= 2) {
1982 QV4::ScopedValue v(scope, (*args)[1]);
1983 if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
1984 qmlWarning(
this) << tr(
"createObject: value is not an object");
1985 args->setReturnValue(QV4::Encode::null());
1991 QQmlContext *ctxt = creationContext();
1992 if (!ctxt) ctxt = d->m_engine->rootContext();
1994 QObject *rv = beginCreate(ctxt);
1997 args->setReturnValue(QV4::Encode::null());
2001 QQmlComponent_setQmlParent(rv, parent);
2003 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4, rv));
2004 Q_ASSERT(object->isObject());
2006 if (!valuemap->isUndefined()) {
2007 QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->qmlContext());
2008 QQmlComponentPrivate::setInitialProperties(
2009 v4, qmlContext, object, valuemap, d->m_state.requiredProperties(), rv,
2010 d->m_state.creator());
2012 if (d->m_state.hasUnsetRequiredProperties()) {
2013 QList<QQmlError> errors;
2014 for (
const auto &requiredProperty: std::as_const(*d->m_state.requiredProperties())) {
2015 errors.push_back(QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(requiredProperty));
2017 qmlWarning(rv, errors);
2018 args->setReturnValue(QV4::Encode::null());
2023 d->completeCreate();
2025 Q_ASSERT(QQmlData::get(rv));
2026 QQmlData::get(rv)->explicitIndestructibleSet =
false;
2027 QQmlData::get(rv)->indestructible =
false;
2029 args->setReturnValue(object->asReturnedValue());
2034
2035
2036QObject *QQmlComponent::createObject(QObject *parent,
const QVariantMap &properties)
2039 Q_ASSERT(d->m_engine);
2040 QObject *rv = d->createWithProperties(
2041 parent, properties, creationContext(), QQmlComponentPrivate::CreateBehavior::Qml);
2043 QQmlData *qmlData = QQmlData::get(rv);
2045 qmlData->explicitIndestructibleSet =
false;
2046 qmlData->indestructible =
false;
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2107
2108
2109void QQmlComponent::incubateObject(QQmlV4FunctionPtr args)
2112 Q_ASSERT(d->m_engine);
2115 QV4::ExecutionEngine *v4 = args->v4engine();
2116 QV4::Scope scope(v4);
2118 QObject *parent =
nullptr;
2119 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
2120 QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous;
2122 if (args->length() >= 1) {
2123 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
2125 parent = qobjectWrapper->object();
2128 if (args->length() >= 2) {
2129 QV4::ScopedValue v(scope, (*args)[1]);
2131 }
else if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
2132 qmlWarning(
this) << tr(
"createObject: value is not an object");
2133 args->setReturnValue(QV4::Encode::null());
2140 if (args->length() >= 3) {
2141 QV4::ScopedValue val(scope, (*args)[2]);
2142 quint32 v = val->toUInt32();
2144 mode = QQmlIncubator::Asynchronous;
2146 mode = QQmlIncubator::AsynchronousIfNested;
2149 QQmlComponentExtension *e = componentExtension(args->v4engine());
2151 QV4::Scoped<QV4::QmlIncubatorObject> r(scope, v4->memoryManager->allocate<QV4::QmlIncubatorObject>(mode));
2152 QV4::ScopedObject p(scope, e->incubationProto.value());
2153 r->setPrototypeOf(p);
2155 if (!valuemap->isUndefined())
2156 r->d()->valuemapOrObject.set(scope.engine, valuemap);
2157 r->d()->qmlContext.set(scope.engine, v4->qmlContext());
2158 r->d()->parent = parent;
2160 QQmlIncubator *incubator = r->d()->incubator;
2161 create(*incubator, creationContext());
2163 if (incubator->status() == QQmlIncubator::Null) {
2164 args->setReturnValue(QV4::Encode::null());
2166 args->setReturnValue(r.asReturnedValue());
2171void QQmlComponentPrivate::initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext,
const QV4::Value &valuemap, QObject *toCreate, RequiredProperties *requiredProperties)
2173 QV4::ExecutionEngine *v4engine = m_engine->handle();
2174 QV4::Scope scope(v4engine);
2176 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate));
2177 Q_ASSERT(object->as<QV4::Object>());
2179 if (!valuemap.isUndefined()) {
2180 setInitialProperties(
2181 v4engine, qmlContext, object, valuemap, requiredProperties, toCreate, m_state.creator());
2185QQmlComponentExtension::QQmlComponentExtension(QV4::ExecutionEngine *v4)
2187 QV4::Scope scope(v4);
2188 QV4::ScopedObject proto(scope, v4->newObject());
2189 proto->defineAccessorProperty(QStringLiteral(
"onStatusChanged"),
2190 QV4::QmlIncubatorObject::method_get_statusChanged, QV4::QmlIncubatorObject::method_set_statusChanged);
2191 proto->defineAccessorProperty(QStringLiteral(
"status"), QV4::QmlIncubatorObject::method_get_status,
nullptr);
2192 proto->defineAccessorProperty(QStringLiteral(
"object"), QV4::QmlIncubatorObject::method_get_object,
nullptr);
2193 proto->defineDefaultProperty(QStringLiteral(
"forceCompletion"), QV4::QmlIncubatorObject::method_forceCompletion);
2195 incubationProto.set(v4, proto);
2198QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_object(
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::QObjectWrapper::wrap(scope.engine, o->d()->incubator->object());
2208QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_forceCompletion(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2210 QV4::Scope scope(b);
2211 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2215 o->d()->incubator->forceCompletion();
2220QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_status(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2222 QV4::Scope scope(b);
2223 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2227 return QV4::Encode(o->d()->incubator->status());
2230QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2232 QV4::Scope scope(b);
2233 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2237 return QV4::Encode(o->d()->statusChanged);
2240QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_set_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *argv,
int argc)
2242 QV4::Scope scope(b);
2243 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2247 o->d()->statusChanged.set(scope.engine, argv[0]);
2252QQmlComponentExtension::~QQmlComponentExtension()
2256void QV4::Heap::QmlIncubatorObject::init(QQmlIncubator::IncubationMode m)
2259 valuemapOrObject.set(internalClass->engine, QV4::Value::undefinedValue());
2260 statusChanged.set(internalClass->engine, QV4::Value::undefinedValue());
2262 qmlContext.set(internalClass->engine,
nullptr);
2263 incubator =
new QQmlComponentIncubator(
this, m);
2266void QV4::Heap::QmlIncubatorObject::destroy() {
2274 QQmlComponent_setQmlParent(o, d()->parent);
2276 if (!d()->valuemapOrObject.isUndefined()) {
2277 QV4::ExecutionEngine *v4 = engine();
2278 QV4::Scope scope(v4);
2279 QV4::ScopedObject obj(scope, QV4::QObjectWrapper::wrap(v4, o));
2280 QV4::Scoped<QV4::QmlContext> qmlCtxt(scope, d()->qmlContext);
2281 QQmlComponentPrivate::setInitialProperties(
2282 v4, qmlCtxt, obj, d()->valuemapOrObject, requiredProperties, o,
2283 QQmlIncubatorPrivate::get(d()->incubator)->creator.data());
2289 QV4::Scope scope(engine());
2291 QObject *object = d()->incubator->object();
2293 if (s == QQmlIncubator::Ready) {
2296 d()->valuemapOrObject.set(scope.engine, QV4::QObjectWrapper::wrap(scope.engine, object));
2298 QQmlData *ddata = QQmlData::get(object);
2300 ddata->explicitIndestructibleSet =
false;
2301 ddata->indestructible =
false;
2304 QV4::ScopedFunctionObject f(scope, d()->statusChanged);
2306 QV4::JSCallArguments jsCallData(scope, 1);
2307 *jsCallData.thisObject =
this;
2308 jsCallData.args[0] = QV4::Value::fromUInt32(s);
2309 f->call(jsCallData);
2310 if (scope.hasException()) {
2311 QQmlError error = scope.engine->catchExceptionAsQmlError();
2312 QQmlEnginePrivate::warning(QQmlEnginePrivate::get(scope.engine->qmlEngine()), error);
2316 if (s != QQmlIncubator::Loading)
2317 d()->incubator->incubatorObject.clear();
2320#undef INITIALPROPERTIES_SOURCE
2324#include "moc_qqmlcomponent.cpp"
2325#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)