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
229
230
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
275
276
277
278
279
280
281
282
283
286
287
288
289
290
291
292
293
295void QQmlComponentPrivate::ready(QQmlNotifyingBlob *)
299 Q_ASSERT(m_typeData);
301 fromTypeData(m_typeData);
304 emit q->statusChanged(q->status());
307void QQmlComponentPrivate::progress(QQmlNotifyingBlob *, qreal p)
312void QQmlComponentPrivate::fromTypeData(
const QQmlRefPointer<QQmlTypeData> &data)
314 m_url = data->finalUrl();
315 if (
auto cu = data->compilationUnit())
316 m_compilationUnit = m_engine->handle()->executableCompilationUnit(std::move(cu));
318 if (!m_compilationUnit) {
319 Q_ASSERT(data->isError());
320 m_state.errors.clear();
321 m_state.appendErrors(data->errors());
325bool QQmlComponentPrivate::hadTopLevelRequiredProperties()
const
327 return m_state.creator()->componentHadTopLevelRequiredProperties();
330void QQmlComponentPrivate::clear()
333 m_typeData->unregisterCallback(
this);
338 m_loadHelper->unregisterCallback(
this);
339 m_loadHelper.reset();
342 m_compilationUnit.reset();
343 m_inlineComponentName.reset();
346QObject *QQmlComponentPrivate::doBeginCreate(QQmlComponent *q, QQmlContext *context)
350 qWarning(
"QQmlComponent: Must provide an engine before calling create");
354 context = m_engine->rootContext();
355 return q->beginCreate(context);
359 QV4::Value *object,
const QString &propertyName,
const QQmlObjectCreator *creator)
364 QV4::QObjectWrapper *wrapper = object->as<QV4::QObjectWrapper>();
368 QObject *o = wrapper->object();
372 if (QQmlData *ddata = QQmlData::get(o)) {
374 propertyName, o, ddata->outerContext);
375 if (propData && propData->acceptsQBinding())
376 creator->removePendingBinding(o, propData->coreIndex());
380 const QMetaObject *meta = o->metaObject();
382 const int index = meta->indexOfProperty(propertyName.toUtf8());
383 if (index != -1 && meta->property(index).isBindable())
384 creator->removePendingBinding(o, index);
387bool QQmlComponentPrivate::setInitialProperty(
388 QObject *base,
const QString &name,
const QVariant &value)
390 bool isComplexProperty = name.contains(u'.');
393 if (m_state.hasUnsetRequiredProperties() && !isComplexProperty)
394 prop = QQmlComponentPrivate::removePropertyFromRequired(
395 base, name, m_state.requiredProperties(), m_engine);
396 else if (QQmlContext *ctxt = qmlContext(base); ctxt)
397 prop = QQmlProperty(base, name, ctxt);
399 prop = QQmlProperty(base, name, m_engine);
401 if (!prop.isValid()) {
405 if (!isComplexProperty)
409 const QStringList properties = name.split(u'.');
410 QV4::Scope scope(m_engine->handle());
411 QV4::ScopedObject object(scope, QV4::QObjectWrapper::wrap(scope.engine, base));
412 QV4::ScopedString segment(scope);
413 for (
int i = 0; i < properties.size() - 1; ++i) {
414 segment = scope.engine->newString(properties.at(i));
415 object = object->get(segment);
416 if (scope.engine->hasException || object->isNullOrUndefined())
420 const QString lastProperty = properties.last();
421 if (!object->isNullOrUndefined()) {
422 segment = scope.engine->newString(lastProperty);
423 QV4::ScopedValue v(scope, scope.engine->metaTypeToJS(value.metaType(), value.constData()));
424 object->put(segment, v);
429 if (scope.engine->hasException) {
430 qmlWarning(base, scope.engine->catchExceptionAsQmlError());
431 scope.engine->hasException =
false;
435 removePendingQPropertyBinding(object, lastProperty, m_state.creator());
439 if (QQmlPropertyPrivate::get(prop)->writeValueProperty(value, {})) {
440 if (prop.isBindable()) {
441 if (QQmlObjectCreator *creator = m_state.creator())
442 creator->removePendingBinding(prop.object(), prop.index());
449 error.setDescription(QStringLiteral(
"Could not set initial property %1").arg(name));
450 qmlWarning(base, error);
455
456
457QQmlComponent::QQmlComponent(QObject *parent)
458 : QObject(*(
new QQmlComponentPrivate), parent)
463
464
465QQmlComponent::~QQmlComponent()
469 if (d->m_state.isCompletePending()) {
470 qWarning(
"QQmlComponent: Component destroyed while completion pending");
473 qWarning() <<
"This may have been caused by one of the following errors:";
474 for (
const QQmlComponentPrivate::AnnotatedQmlError &e : std::as_const(d->m_state.errors))
475 qWarning().nospace().noquote() << QLatin1String(
" ") << e.error;
479 if (d->m_state.hasCreator())
484 d->m_typeData->unregisterCallback(d);
485 if (d->m_engine && !d->m_typeData->isCompleteOrError()) {
488 QQmlTypeLoader::get(d->m_engine)->drop(QQmlDataBlob::Ptr(d->m_typeData.data()));
490 d->m_typeData.reset();
495
496
497
498
499
500
501
502
503
504
505
508
509
510
511QQmlComponent::Status QQmlComponent::status()
const
513 Q_D(
const QQmlComponent);
517 else if (!d->m_state.errors.isEmpty())
519 else if (d->m_engine && (d->m_compilationUnit || d->loadedType().isValid()))
521 else if (d->m_loadHelper)
528
529
530bool QQmlComponent::isNull()
const
532 return status() == Null;
536
537
538bool QQmlComponent::isReady()
const
540 return status() == Ready;
544
545
546bool QQmlComponent::isError()
const
548 return status() == Error;
552
553
554bool QQmlComponent::isLoading()
const
556 return status() == Loading;
560
561
562
563
564
565bool QQmlComponent::isBound()
const
567 Q_D(
const QQmlComponent);
572
573
574
575
578
579
580
581
582qreal QQmlComponent::progress()
const
584 Q_D(
const QQmlComponent);
585 return d->m_progress;
589
590
591
592
593
596
597
598
599
600
603
604
605
606QQmlComponent::QQmlComponent(QQmlEngine *engine, QObject *parent)
607 : QObject(*(
new QQmlComponentPrivate), parent)
610 d->m_engine = engine;
611 QObject::connect(engine, &QObject::destroyed,
this, [d]() {
613 d->m_engine =
nullptr;
618
619
620
621
622
623
624
625QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QUrl &url, QObject *parent)
626 : QQmlComponent(engine, url, QQmlComponent::PreferSynchronous, parent)
631
632
633
634
635
636
637
638
639QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QUrl &url, CompilationMode mode,
641 : QQmlComponent(engine, parent)
644 d->loadUrl(url, mode);
648
649
650
651
652
653
654
655
656QQmlComponent::QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, QObject *parent)
657 : QQmlComponent(engine, uri, typeName, QQmlComponent::PreferSynchronous, parent)
663
664
665
666
667
668
669
670
671QQmlComponent::QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, CompilationMode mode, QObject *parent)
672 : QQmlComponent(engine, parent)
674 loadFromModule(uri, typeName, mode);
678
679
680
681
682
683QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QString &fileName,
685 : QQmlComponent(engine, fileName, QQmlComponent::PreferSynchronous, parent)
690
691
692
693
694
695
696QQmlComponent::QQmlComponent(QQmlEngine *engine,
const QString &fileName,
697 CompilationMode mode, QObject *parent)
698 : QQmlComponent(engine, parent)
701 if (fileName.startsWith(u':'))
702 d->loadUrl(QUrl(QLatin1String(
"qrc") + fileName), mode);
703 else if (QDir::isAbsolutePath(fileName))
704 d->loadUrl(QUrl::fromLocalFile(fileName), mode);
706 d->loadUrl(QUrl(fileName), mode);
710
711
712QQmlComponent::QQmlComponent(QQmlEngine *engine, QV4::ExecutableCompilationUnit *compilationUnit,
713 int start, QObject *parent)
714 : QQmlComponent(engine, parent)
717 d->m_compilationUnit.reset(compilationUnit);
719 d->m_url = compilationUnit->finalUrl();
723void QQmlComponentPrivate::setData(
const QByteArray &data,
const QUrl &url, QQmlComponent::CompilationMode compilationMode)
727 qWarning(
"QQmlComponent: Must provide an engine before calling setData");
738 m_engine->handle()->trimCompilationUnitsForUrl(url);
740 QQmlTypeLoader::Mode mode = compilationMode == QQmlComponent::Asynchronous
741 ? QQmlTypeLoader::Asynchronous
742 : QQmlTypeLoader::PreferSynchronous;
743 QQmlRefPointer<QQmlTypeData> typeData = QQmlTypeLoader::get(m_engine)->getType(data, url, mode);
745 if (typeData->isCompleteOrError()) {
746 fromTypeData(typeData);
749 m_typeData = typeData;
750 m_typeData->registerCallback(
this);
751 setProgress(typeData->progress());
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
775QQmlContext *QQmlComponent::creationContext()
const
777 Q_D(
const QQmlComponent);
778 if (!d->m_creationContext.isNull())
779 return d->m_creationContext->asQQmlContext();
781 return qmlContext(
this);
785
786
787
788
789QQmlEngine *QQmlComponent::engine()
const
791 Q_D(
const QQmlComponent);
796
797
798
799
800void QQmlComponent::loadUrl(
const QUrl &url)
807
808
809
810
811
812void QQmlComponent::loadUrl(
const QUrl &url, QQmlComponent::CompilationMode mode)
815 d->loadUrl(url, mode);
818void QQmlComponentPrivate::loadUrl(
const QUrl &newUrl, QQmlComponent::CompilationMode mode)
823 if (newUrl.isRelative()) {
825 m_url = m_engine->baseUrl().resolved(QUrl(newUrl.toString()));
826 }
else if (m_engine->baseUrl().isLocalFile() && newUrl.isLocalFile() && !QDir::isAbsolutePath(newUrl.toLocalFile())) {
830 QUrl fixedUrl(newUrl);
831 fixedUrl.setScheme(QString());
834 m_url = m_engine->baseUrl().resolved(fixedUrl);
839 if (m_url.scheme() ==
"qrc"_L1 && !m_url.path().startsWith(
"/"_L1)) {
840 qWarning().nospace().noquote()
841 <<
"QQmlComponent: attempted to load via a relative URL '" << m_url.toString()
842 <<
"' in resource file system. This is not fully supported and may not work";
845 if (newUrl.isEmpty()) {
847 error.setDescription(QQmlComponent::tr(
"Invalid empty URL"));
848 m_state.errors.emplaceBack(error);
854 QQmlTypeLoader::Mode loaderMode = (mode == QQmlComponent::Asynchronous)
855 ? QQmlTypeLoader::Asynchronous
856 : QQmlTypeLoader::PreferSynchronous;
857 QQmlRefPointer<QQmlTypeData> data = QQmlTypeLoader::get(m_engine)->getType(m_url, loaderMode);
859 if (data->isCompleteOrError()) {
864 m_typeData->registerCallback(
this);
865 setProgress(data->progress());
868 emit q->statusChanged(q->status());
872
873
874
875QList<QQmlError> QQmlComponent::errors()
const
877 Q_D(
const QQmlComponent);
878 QList<QQmlError> errors;
879 errors.reserve(d->m_state.errors.size());
880 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors)
881 errors.emplaceBack(annotated.error);
886
887
888
889
890
891
892
893
894
897
898
899
900QString QQmlComponent::errorString()
const
902 Q_D(
const QQmlComponent);
906 for (
const QQmlComponentPrivate::AnnotatedQmlError &annotated : d->m_state.errors) {
907 ret += annotated.error.toString() + QLatin1Char(
'\n');
913
914
915
918
919
920
921
922QUrl QQmlComponent::url()
const
924 Q_D(
const QQmlComponent);
929
930
931QQmlComponent::QQmlComponent(QQmlComponentPrivate &dd, QObject *parent)
932 : QObject(dd, parent)
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952QObject *QQmlComponent::create(QQmlContext *context)
955 return d->createWithProperties(
956 nullptr, QVariantMap {}, context, QQmlComponentPrivate::CreateBehavior::Cpp);
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979QObject *QQmlComponent::createWithInitialProperties(
980 const QVariantMap& initialProperties, QQmlContext *context)
983 return d->createWithProperties(
984 nullptr, initialProperties, context, QQmlComponentPrivate::CreateBehavior::Cpp);
990
991QObject *QQmlComponentPrivate::createWithProperties(
992 QObject *parent,
const QVariantMap &properties,
993 QQmlContext *context, CreateBehavior behavior)
997 QObject *rv = doBeginCreate(q, context);
999 if (m_state.isCompletePending()) {
1003 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
1004 complete(ep, &m_state);
1010 QQmlComponent_setQmlParent(rv, parent);
1012 if (behavior == CreateBehavior::Qml) {
1014 for (
auto it = properties.cbegin(), end = properties.cend(); it != end; ++it)
1015 ok = setInitialProperty(rv, it.key(), it.value()) && ok;
1016 q->completeCreate();
1017 if (m_state.hasUnsetRequiredProperties()) {
1018 for (
const auto &unsetRequiredProperty : std::as_const(*m_state.requiredProperties())) {
1019 const QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1020 qmlWarning(rv, error);
1022 delete std::exchange(rv,
nullptr);
1025 delete std::exchange(rv,
nullptr);
1028 setInitialProperties(rv, properties);
1029 q->completeCreate();
1030 if (m_state.hasUnsetRequiredProperties())
1031 delete std::exchange(rv,
nullptr);
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074QObject *QQmlComponent::beginCreate(QQmlContext *context)
1078 return d->beginCreate(QQmlContextData::get(context));
1083 const int parserStatusCast = type.parserStatusCast();
1084 return parserStatusCast == -1
1086 :
reinterpret_cast<QQmlParserStatus *>(
reinterpret_cast<
char *>(rv) + parserStatusCast);
1089QObject *QQmlComponentPrivate::beginCreate(QQmlRefPointer<QQmlContextData> context)
1092 auto cleanup = qScopeGuard([
this] {
1093 if (!m_state.errors.isEmpty() && lcQmlComponentGeneral().isDebugEnabled()) {
1094 for (
const auto &e : std::as_const(m_state.errors)) {
1095 qCDebug(lcQmlComponentGeneral) <<
"QQmlComponent: " << e.error.toString();
1100 qWarning(
"QQmlComponent: Cannot create a component in a null context");
1104 if (!context->isValid()) {
1105 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1109 if (context->engine() != m_engine) {
1110 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1114 if (m_state.isCompletePending()) {
1115 qWarning(
"QQmlComponent: Cannot create new component instance before completing the previous");
1121 m_state.errors.removeIf([](
const auto &e) {
return e.isTransient; });
1122 m_state.clearRequiredProperties();
1124 if (!q->isReady()) {
1125 qWarning(
"QQmlComponent: Component is not ready");
1130 static const int maxCreationDepth = 10;
1131 if (creationDepth >= maxCreationDepth) {
1132 qWarning(
"QQmlComponent: Component creation is recursing - aborting");
1136 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(m_engine);
1138 enginePriv->inProgressCreations++;
1139 m_state.errors.clear();
1140 m_state.setCompletePending(
true);
1142 QObject *rv =
nullptr;
1143 auto setupDData = [&]() {
1144 QQmlData *ddata = QQmlData::get(rv);
1148 ddata->indestructible =
true;
1149 ddata->explicitIndestructibleSet =
true;
1150 ddata->rootObjectInCreation =
false;
1153 if (!ddata->outerContext)
1154 ddata->outerContext = context.data();
1155 if (!ddata->context)
1156 ddata->context = context.data();
1159 const QQmlType type = loadedType();
1160 if (!type.isValid()) {
1161 enginePriv->referenceScarceResources();
1162 const QString *icName = m_inlineComponentName.get();
1163 m_state.initCreator(
1164 context, m_compilationUnit, m_creationContext, icName ? *icName : QString());
1166 QQmlObjectCreator::CreationFlags flags;
1168 flags = QQmlObjectCreator::InlineComponent;
1170 m_start = m_compilationUnit->inlineComponentId(*icName);
1171 Q_ASSERT(m_start > 0);
1173 flags = QQmlObjectCreator::NormalObject;
1176 rv = m_state.creator()->create(m_start,
nullptr,
nullptr, flags);
1178 m_state.appendCreatorErrors();
1181 enginePriv->dereferenceScarceResources();
1184 rv = type.createWithQQmlData();
1185 QQmlPropertyCache::ConstPtr propertyCache = QQmlData::ensurePropertyCache(rv);
1187 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv)) {
1188 parserStatus->classBegin();
1189 m_state.ensureRequiredPropertyStorage(rv);
1190 }
else if (type.finalizerCast() != -1) {
1191 m_state.ensureRequiredPropertyStorage(rv);
1194 if (propertyCache) {
1195 for (
int i = 0, propertyCount = propertyCache->propertyCount(); i < propertyCount; ++i) {
1196 if (
const QQmlPropertyData *propertyData = propertyCache->property(i); propertyData->isRequired()) {
1197 m_state.ensureRequiredPropertyStorage(rv);
1198 RequiredPropertyInfo info;
1199 info.propertyName = propertyData->name(rv);
1200 m_state.addPendingRequiredProperty(rv, propertyData, info);
1213void QQmlComponentPrivate::beginDeferred(QQmlEnginePrivate *enginePriv,
1214 QObject *object, DeferredState *deferredState)
1216 QQmlData *ddata = QQmlData::get(object);
1217 Q_ASSERT(!ddata->deferredData.isEmpty());
1219 deferredState->reserve(ddata->deferredData.size());
1221 for (QQmlData::DeferredData *deferredData : std::as_const(ddata->deferredData)) {
1222 enginePriv->inProgressCreations++;
1224 ConstructionState state;
1225 state.setCompletePending(
true);
1227 auto creator = state.initCreator(
1228 deferredData->context->parent(),
1229 deferredData->compilationUnit,
1230 QQmlRefPointer<QQmlContextData>(),
1231 deferredData->inlineComponentName
1234 if (!creator->populateDeferredProperties(object, deferredData))
1235 state.appendCreatorErrors();
1236 deferredData->bindings.clear();
1238 deferredState->push_back(std::move(state));
1242void QQmlComponentPrivate::completeDeferred(QQmlEnginePrivate *enginePriv, QQmlComponentPrivate::DeferredState *deferredState)
1244 for (ConstructionState &state : *deferredState)
1245 complete(enginePriv, &state);
1248void QQmlComponentPrivate::complete(QQmlEnginePrivate *enginePriv, ConstructionState *state)
1250 if (state->isCompletePending()) {
1251 QQmlInstantiationInterrupt interrupt;
1252 state->creator()->finalize(interrupt);
1254 state->setCompletePending(
false);
1256 enginePriv->inProgressCreations--;
1258 if (0 == enginePriv->inProgressCreations) {
1259 while (enginePriv->erroredBindings) {
1260 enginePriv->warning(enginePriv->erroredBindings->removeError());
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283QQmlProperty QQmlComponentPrivate::removePropertyFromRequired(
1284 QObject *target,
const QString &name, RequiredProperties *requiredProperties,
1285 QQmlEngine *engine,
bool *wasInRequiredProperties)
1287 Q_ASSERT(requiredProperties);
1289 const QQmlProperty prop(target, name, engine);
1290 if (!prop.isValid()) {
1291 if (wasInRequiredProperties)
1292 *wasInRequiredProperties =
false;
1296 const QQmlPropertyPrivate *privProp = QQmlPropertyPrivate::get(prop);
1300 const QQmlPropertyData *targetProp = &privProp->core;
1301 QQmlData *data = QQmlData::get(target);
1302 Q_ASSERT(data && data->propertyCache);
1304 if (targetProp->isAlias()) {
1305 if (requiredProperties->remove(
1306 { target, data->propertyCache->property(targetProp->coreIndex()) })) {
1310 QQmlPropertyIndex originalIndex(targetProp->coreIndex());
1311 QQmlPropertyIndex propIndex;
1312 QQmlPropertyPrivate::findAliasTarget(target, originalIndex, &target, &propIndex);
1313 data = QQmlData::get(target);
1314 Q_ASSERT(data && data->propertyCache);
1315 targetProp = data->propertyCache->property(propIndex.coreIndex());
1319 targetProp = data->propertyCache->property(targetProp->coreIndex());
1323 if (requiredProperties->remove({target, targetProp}))
1326 if (wasInRequiredProperties)
1327 *wasInRequiredProperties = found;
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342void QQmlComponent::completeCreate()
1346 d->completeCreate();
1349void QQmlComponentPrivate::completeCreate()
1351 if (m_state.hasUnsetRequiredProperties()) {
1352 for (
const auto& unsetRequiredProperty: std::as_const(*m_state.requiredProperties())) {
1353 QQmlError error = unsetRequiredPropertyToQQmlError(unsetRequiredProperty);
1354 m_state.errors.push_back(QQmlComponentPrivate::AnnotatedQmlError { error,
true });
1358 const QQmlType type = loadedType();
1359 if (type.isValid()) {
1360 QObject *rv = m_state.target();
1361 if (QQmlParserStatus *parserStatus = parserStatusCast(type, rv))
1362 parserStatus->componentComplete();
1364 if (
const int finalizerCast = type.finalizerCast(); finalizerCast != -1) {
1365 auto *hook =
reinterpret_cast<QQmlFinalizerHook *>(
1366 reinterpret_cast<
char *>(rv) + finalizerCast);
1367 hook->componentFinalized();
1371
1372
1373
1374
1375 m_state.setCompletePending(
false);
1376 QQmlEnginePrivate::get(m_engine)->inProgressCreations--;
1377 }
else if (m_state.isCompletePending()) {
1379 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(m_engine);
1380 complete(ep, &m_state);
1385QQmlComponentAttached::QQmlComponentAttached(QObject *parent)
1386: QObject(parent), m_prev(
nullptr), m_next(
nullptr)
1390QQmlComponentAttached::~QQmlComponentAttached()
1392 if (m_prev) *m_prev = m_next;
1393 if (m_next) m_next->m_prev = m_prev;
1399
1400
1401QQmlComponentAttached *QQmlComponent::qmlAttachedProperties(QObject *obj)
1403 QQmlComponentAttached *a =
new QQmlComponentAttached(obj);
1405 QQmlEngine *engine = qmlEngine(obj);
1409 QQmlEnginePrivate *p = QQmlEnginePrivate::get(engine);
1410 if (p->activeObjectCreator) {
1411 a->insertIntoList(p->activeObjectCreator->componentAttachment());
1413 QQmlData *d = QQmlData::get(obj);
1415 Q_ASSERT(d->context);
1416 d->context->addComponentAttached(a);
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439void QQmlComponent::loadFromModule(QAnyStringView uri, QAnyStringView typeName,
1440 QQmlComponent::CompilationMode mode)
1444 QQmlTypeLoader::Mode typeLoaderMode = QQmlTypeLoader::Synchronous;
1446 case QQmlComponent::PreferSynchronous:
1447 typeLoaderMode = QQmlTypeLoader::PreferSynchronous;
1449 case QQmlComponent::Asynchronous:
1450 typeLoaderMode = QQmlTypeLoader::Asynchronous;
1454 d->prepareLoadFromModule(uri, typeName, typeLoaderMode);
1455 if (d->m_loadHelper->isCompleteOrError())
1456 d->completeLoadFromModule(uri, typeName);
1458 d->m_loadHelper->registerCallback(d);
1461void QQmlComponentPrivate::prepareLoadFromModule(
1462 QAnyStringView uri, QAnyStringView typeName, QQmlTypeLoader::Mode mode)
1466 m_loadHelper->unregisterCallback(
this);
1469 m_loadHelper = QQml::makeRefPointer<LoadHelper>(QQmlTypeLoader::get(m_engine), uri, typeName, mode);
1472void QQmlComponentPrivate::completeLoadFromModule(QAnyStringView uri, QAnyStringView typeName)
1477 auto reportError = [&](QString msg) {
1479 error.setDescription(msg);
1480 m_state.errors.push_back(std::move(error));
1482 emit q->statusChanged(q->Error);
1484 auto emitComplete = [&]() {
1486 emit q->statusChanged(q->status());
1491 const QQmlType type = m_loadHelper->type();
1493 if (m_loadHelper->resolveTypeResult() == LoadHelper::ResolveTypeResult::NoSuchModule) {
1494 reportError(QLatin1String(R"(No module named "%1" found)").arg(uri.toString()));
1495 }
else if (!type.isValid()) {
1496 reportError(QLatin1String(R"(Module "%1" contains no type named "%2")")
1497 .arg(uri.toString(), typeName.toString()));
1498 }
else if (type.isCreatable()) {
1500 }
else if (type.isInlineComponent()) {
1501 auto baseUrl = type.sourceUrl();
1502 baseUrl.setFragment(QString());
1504 Q_ASSERT(m_progress == 0.0);
1508 QSignalBlocker blockSignals(q);
1510 loadUrl(baseUrl, QQmlComponent::PreferSynchronous);
1513 if (m_progress != 0.0)
1514 emit q->progressChanged(m_progress);
1520 QString elementName = type.elementName();
1521 if (m_compilationUnit->inlineComponentId(elementName) == -1) {
1522 QString realTypeName = typeName.toString();
1523 realTypeName.truncate(realTypeName.indexOf(u'.'));
1524 QString errorMessage = R"(Type "%1" from module "%2" contains no inline component named "%3".)"_L1.arg(
1525 realTypeName, uri.toString(), elementName);
1526 if (elementName == u"qml")
1527 errorMessage +=
" To load the type \"%1\", drop the \".qml\" extension."_L1.arg(realTypeName);
1528 reportError(std::move(errorMessage));
1530 m_inlineComponentName = std::make_unique<QString>(std::move(elementName));
1533 }
else if (type.isComposite()) {
1534 QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous;
1535 switch (m_loadHelper->mode()) {
1536 case QQmlTypeLoader::Asynchronous:
1537 mode = QQmlComponent::Asynchronous;
1539 case QQmlTypeLoader::PreferSynchronous:
1540 case QQmlTypeLoader::Synchronous:
1541 mode = QQmlComponent::PreferSynchronous;
1546 loadUrl(type.sourceUrl(), mode);
1547 }
else if (type.isSingleton()) {
1549 reportError(QLatin1String(R"(%1 is a singleton, and cannot be loaded)").arg(typeName.toString()));
1551 reportError(QLatin1String(
"Could not load %1, as the type is uncreatable").arg(typeName.toString()));
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1575void QQmlComponent::create(QQmlIncubator &incubator, QQmlContext *context, QQmlContext *forContext)
1580 context = d->m_engine->rootContext();
1582 QQmlRefPointer<QQmlContextData> contextData = QQmlContextData::get(context);
1583 QQmlRefPointer<QQmlContextData> forContextData =
1584 forContext ? QQmlContextData::get(forContext) : contextData;
1586 if (!contextData->isValid()) {
1587 qWarning(
"QQmlComponent: Cannot create a component in an invalid context");
1591 if (contextData->engine() != d->m_engine) {
1592 qWarning(
"QQmlComponent: Must create component in context from the same QQmlEngine");
1597 qWarning(
"QQmlComponent: Component is not ready");
1602 QExplicitlySharedDataPointer<QQmlIncubatorPrivate> p(incubator.d);
1604 if (d->loadedType().isValid()) {
1608 p->incubateCppBasedComponent(
this, context);
1612 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(d->m_engine);
1614 p->compilationUnit = d->m_compilationUnit;
1615 p->enginePriv = enginePriv;
1616 p->creator.reset(
new QQmlObjectCreator(
1617 contextData, d->m_compilationUnit, d->m_creationContext,
1618 d->m_inlineComponentName ? *d->m_inlineComponentName : QString(), p.data()));
1619 p->subComponentToCreate = d->m_start;
1621 enginePriv->incubate(incubator, forContextData);
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647void QQmlComponent::setInitialProperties(QObject *object,
const QVariantMap &properties)
1650 d->setInitialProperties(object, properties);
1653bool QQmlComponentPrivate::setInitialProperties(QObject *object,
const QVariantMap &properties)
1656 for (
auto it = properties.constBegin(); it != properties.constEnd(); ++it) {
1657 if (it.key().contains(u'.')) {
1658 auto segments = it.key().split(u'.');
1659 QString description = u"Setting initial properties failed: Cannot initialize nested "_s
1661 if (segments.size() >= 2) {
1662 QString s = u" To set %1.%2 as an initial property, create %1, set its "_s
1663 u"property %2, and pass %1 as an initial property."_s;
1664 description += s.arg(segments[0], segments[1]);
1667 error.setUrl(m_url);
1668 error.setDescription(description);
1669 qmlWarning(object, error);
1674 result = setInitialProperty(object, it.key(), it.value()) && result;
1680
1681
1682
1683
1684
1685
1686void QQmlComponentPrivate::incubateObject(
1687 QQmlIncubator *incubationTask,
1688 QQmlComponent *component,
1690 const QQmlRefPointer<QQmlContextData> &context,
1691 const QQmlRefPointer<QQmlContextData> &forContext)
1693 QQmlIncubatorPrivate *incubatorPriv = QQmlIncubatorPrivate::get(incubationTask);
1694 QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(engine);
1695 QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component);
1697 incubatorPriv->compilationUnit = componentPriv->m_compilationUnit;
1698 incubatorPriv->enginePriv = enginePriv;
1699 incubatorPriv->creator.reset(
new QQmlObjectCreator(
1700 context, componentPriv->m_compilationUnit, componentPriv->m_creationContext,
1701 m_inlineComponentName ? *m_inlineComponentName : QString()));
1703 if (m_start == -1) {
1704 if (
const QString *icName = componentPriv->m_inlineComponentName.get()) {
1705 m_start = m_compilationUnit->inlineComponentId(*icName);
1706 Q_ASSERT(m_start > 0);
1709 incubatorPriv->subComponentToCreate = componentPriv->m_start;
1711 enginePriv->incubate(*incubationTask, forContext);
1722#define QmlIncubatorObjectMembers(class, Member)
1723 Member(class, HeapValue, HeapValue, valuemapOrObject)
1724 Member(class, HeapValue, HeapValue, statusChanged)
1725 Member(class, Pointer, QmlContext *, qmlContext)
1726 Member(class, NoMark, QQmlComponentIncubator *, incubator)
1727 Member(class, NoMark, QV4QPointer<QObject>, parent)
1730 DECLARE_MARKOBJECTS(QmlIncubatorObject)
1732 void init(QQmlIncubator::IncubationMode = QQmlIncubator::Asynchronous);
1733 inline void destroy();
1763 incubatorObject.set(inc->internalClass->engine, inc);
1767 QV4::Scope scope(incubatorObject.engine());
1768 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1769 i->statusChanged(s);
1773 QV4::Scope scope(incubatorObject.engine());
1774 QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject.as<QV4::QmlIncubatorObject>());
1775 auto d = QQmlIncubatorPrivate::get(
this);
1776 i->setInitialState(o, d->requiredProperties());
1786 me->setParent(parent);
1787 typedef QQmlPrivate::AutoParentFunction APF;
1788 QList<APF> functions = QQmlMetaType::parentFunctions();
1790 bool needParent =
false;
1791 for (
int ii = 0; ii < functions.size(); ++ii) {
1792 QQmlPrivate::AutoParentResult res = functions.at(ii)(me, parent);
1793 if (res == QQmlPrivate::Parented) {
1796 }
else if (res == QQmlPrivate::IncompatibleParent) {
1801 qmlWarning(me) <<
"Created graphical object was not placed in the graphics scene.";
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1848void QQmlComponentPrivate::setInitialProperties(
1849 QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext,
const QV4::Value &o,
1850 const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent,
1851 const QQmlObjectCreator *creator)
1853 QV4::Scope scope(engine);
1854 QV4::ScopedObject object(scope);
1855 QV4::ScopedObject valueMap(scope, v);
1856 QV4::ObjectIterator it(scope, valueMap, QV4::ObjectIterator::EnumerableOnly);
1857 QV4::ScopedString name(scope);
1858 QV4::ScopedValue val(scope);
1859 if (engine->hasException)
1863 QV4::ScopedStackFrame frame(scope, qmlContext ? qmlContext : engine->scriptContext());
1866 name = it.nextPropertyNameAsString(val);
1870 const QStringList properties = name->toQString().split(QLatin1Char(
'.'));
1871 bool isTopLevelProperty = properties.size() == 1;
1872 for (
int i = 0; i < properties.size() - 1; ++i) {
1873 name = engine->newString(properties.at(i));
1874 object = object->get(name);
1875 if (engine->hasException || !object) {
1879 if (engine->hasException) {
1880 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1885 error.setUrl(qmlContext ? qmlContext->qmlContext()->url() : QUrl());
1886 error.setDescription(QLatin1String(
"Cannot resolve property \"%1\".")
1887 .arg(properties.join(u'.')));
1888 qmlWarning(createdComponent, error);
1891 const QString lastProperty = properties.last();
1892 name = engine->newString(lastProperty);
1893 object->put(name, val);
1894 if (engine->hasException) {
1895 qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
1897 }
else if (isTopLevelProperty && requiredProperties) {
1898 auto prop = removePropertyFromRequired(createdComponent, name->toQString(),
1899 requiredProperties, engine->qmlEngine());
1902 removePendingQPropertyBinding(object, lastProperty, creator);
1905 engine->hasException =
false;
1908QQmlError QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(
const RequiredPropertyInfo &unsetRequiredProperty)
1911 QString description = QLatin1String(
"Required property %1 was not initialized").arg(unsetRequiredProperty.propertyName);
1912 switch (unsetRequiredProperty.aliasesToRequired.size()) {
1916 const auto info = unsetRequiredProperty.aliasesToRequired.first();
1917 description += QLatin1String(
"\nIt can be set via the alias property %1 from %2\n").arg(info.propertyName, info.fileUrl.toString());
1921 description += QLatin1String(
"\nIt can be set via one of the following alias properties:");
1922 for (
const auto &aliasInfo: unsetRequiredProperty.aliasesToRequired) {
1923 description += QLatin1String(
"\n- %1 (%2)").arg(aliasInfo.propertyName, aliasInfo.fileUrl.toString());
1925 description += QLatin1Char(
'\n');
1927 error.setDescription(description);
1928 error.setUrl(unsetRequiredProperty.fileUrl);
1929 error.setLine(qmlConvertSourceCoordinate<quint32,
int>(
1930 unsetRequiredProperty.location.line()));
1931 error.setColumn(qmlConvertSourceCoordinate<quint32,
int>(
1932 unsetRequiredProperty.location.column()));
1936#if QT_DEPRECATED_SINCE(6
, 3
)
1938
1939
1940void QQmlComponent::createObject(QQmlV4FunctionPtr args)
1943 Q_ASSERT(d->m_engine);
1946 qmlWarning(
this) <<
"Unsuitable arguments passed to createObject(). The first argument should "
1947 "be a QObject* or null, and the second argument should be a JavaScript "
1948 "object or a QVariantMap";
1950 QObject *parent =
nullptr;
1951 QV4::ExecutionEngine *v4 = args->v4engine();
1952 QV4::Scope scope(v4);
1953 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
1955 if (args->length() >= 1) {
1956 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
1958 parent = qobjectWrapper->object();
1961 if (args->length() >= 2) {
1962 QV4::ScopedValue v(scope, (*args)[1]);
1963 if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
1964 qmlWarning(
this) << tr(
"createObject: value is not an object");
1965 args->setReturnValue(QV4::Encode::null());
1971 QQmlContext *ctxt = creationContext();
1972 if (!ctxt) ctxt = d->m_engine->rootContext();
1974 QObject *rv = beginCreate(ctxt);
1977 args->setReturnValue(QV4::Encode::null());
1981 QQmlComponent_setQmlParent(rv, parent);
1983 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4, rv));
1984 Q_ASSERT(object->isObject());
1986 if (!valuemap->isUndefined()) {
1987 QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->qmlContext());
1988 QQmlComponentPrivate::setInitialProperties(
1989 v4, qmlContext, object, valuemap, d->m_state.requiredProperties(), rv,
1990 d->m_state.creator());
1992 if (d->m_state.hasUnsetRequiredProperties()) {
1993 QList<QQmlError> errors;
1994 for (
const auto &requiredProperty: std::as_const(*d->m_state.requiredProperties())) {
1995 errors.push_back(QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(requiredProperty));
1997 qmlWarning(rv, errors);
1998 args->setReturnValue(QV4::Encode::null());
2003 d->completeCreate();
2005 Q_ASSERT(QQmlData::get(rv));
2006 QQmlData::get(rv)->explicitIndestructibleSet =
false;
2007 QQmlData::get(rv)->indestructible =
false;
2009 args->setReturnValue(object->asReturnedValue());
2014
2015
2016QObject *QQmlComponent::createObject(QObject *parent,
const QVariantMap &properties)
2019 Q_ASSERT(d->m_engine);
2020 QObject *rv = d->createWithProperties(
2021 parent, properties, creationContext(), QQmlComponentPrivate::CreateBehavior::Qml);
2023 QQmlData *qmlData = QQmlData::get(rv);
2025 qmlData->explicitIndestructibleSet =
false;
2026 qmlData->indestructible =
false;
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2087
2088
2089void QQmlComponent::incubateObject(QQmlV4FunctionPtr args)
2092 Q_ASSERT(d->m_engine);
2095 QV4::ExecutionEngine *v4 = args->v4engine();
2096 QV4::Scope scope(v4);
2098 QObject *parent =
nullptr;
2099 QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
2100 QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous;
2102 if (args->length() >= 1) {
2103 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
2105 parent = qobjectWrapper->object();
2108 if (args->length() >= 2) {
2109 QV4::ScopedValue v(scope, (*args)[1]);
2111 }
else if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
2112 qmlWarning(
this) << tr(
"createObject: value is not an object");
2113 args->setReturnValue(QV4::Encode::null());
2120 if (args->length() >= 3) {
2121 QV4::ScopedValue val(scope, (*args)[2]);
2122 quint32 v = val->toUInt32();
2124 mode = QQmlIncubator::Asynchronous;
2126 mode = QQmlIncubator::AsynchronousIfNested;
2129 QQmlComponentExtension *e = componentExtension(args->v4engine());
2131 QV4::Scoped<QV4::QmlIncubatorObject> r(scope, v4->memoryManager->allocate<QV4::QmlIncubatorObject>(mode));
2132 QV4::ScopedObject p(scope, e->incubationProto.value());
2133 r->setPrototypeOf(p);
2135 if (!valuemap->isUndefined())
2136 r->d()->valuemapOrObject.set(scope.engine, valuemap);
2137 r->d()->qmlContext.set(scope.engine, v4->qmlContext());
2138 r->d()->parent = parent;
2140 QQmlIncubator *incubator = r->d()->incubator;
2141 create(*incubator, creationContext());
2143 if (incubator->status() == QQmlIncubator::Null) {
2144 args->setReturnValue(QV4::Encode::null());
2146 args->setReturnValue(r.asReturnedValue());
2151void QQmlComponentPrivate::initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext,
const QV4::Value &valuemap, QObject *toCreate, RequiredProperties *requiredProperties)
2153 QV4::ExecutionEngine *v4engine = m_engine->handle();
2154 QV4::Scope scope(v4engine);
2156 QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate));
2157 Q_ASSERT(object->as<QV4::Object>());
2159 if (!valuemap.isUndefined()) {
2160 setInitialProperties(
2161 v4engine, qmlContext, object, valuemap, requiredProperties, toCreate, m_state.creator());
2165QQmlComponentExtension::QQmlComponentExtension(QV4::ExecutionEngine *v4)
2167 QV4::Scope scope(v4);
2168 QV4::ScopedObject proto(scope, v4->newObject());
2169 proto->defineAccessorProperty(QStringLiteral(
"onStatusChanged"),
2170 QV4::QmlIncubatorObject::method_get_statusChanged, QV4::QmlIncubatorObject::method_set_statusChanged);
2171 proto->defineAccessorProperty(QStringLiteral(
"status"), QV4::QmlIncubatorObject::method_get_status,
nullptr);
2172 proto->defineAccessorProperty(QStringLiteral(
"object"), QV4::QmlIncubatorObject::method_get_object,
nullptr);
2173 proto->defineDefaultProperty(QStringLiteral(
"forceCompletion"), QV4::QmlIncubatorObject::method_forceCompletion);
2175 incubationProto.set(v4, proto);
2178QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_object(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2180 QV4::Scope scope(b);
2181 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2185 return QV4::QObjectWrapper::wrap(scope.engine, o->d()->incubator->object());
2188QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_forceCompletion(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2190 QV4::Scope scope(b);
2191 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2195 o->d()->incubator->forceCompletion();
2200QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_status(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2202 QV4::Scope scope(b);
2203 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2207 return QV4::Encode(o->d()->incubator->status());
2210QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_get_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
2212 QV4::Scope scope(b);
2213 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2217 return QV4::Encode(o->d()->statusChanged);
2220QV4::ReturnedValue
QV4::
QmlIncubatorObject::method_set_statusChanged(
const FunctionObject *b,
const Value *thisObject,
const Value *argv,
int argc)
2222 QV4::Scope scope(b);
2223 QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>());
2227 o->d()->statusChanged.set(scope.engine, argv[0]);
2232QQmlComponentExtension::~QQmlComponentExtension()
2236void QV4::Heap::QmlIncubatorObject::init(QQmlIncubator::IncubationMode m)
2239 valuemapOrObject.set(internalClass->engine, QV4::Value::undefinedValue());
2240 statusChanged.set(internalClass->engine, QV4::Value::undefinedValue());
2242 qmlContext.set(internalClass->engine,
nullptr);
2243 incubator =
new QQmlComponentIncubator(
this, m);
2246void QV4::Heap::QmlIncubatorObject::destroy() {
2254 QQmlComponent_setQmlParent(o, d()->parent);
2256 if (!d()->valuemapOrObject.isUndefined()) {
2257 QV4::ExecutionEngine *v4 = engine();
2258 QV4::Scope scope(v4);
2259 QV4::ScopedObject obj(scope, QV4::QObjectWrapper::wrap(v4, o));
2260 QV4::Scoped<QV4::QmlContext> qmlCtxt(scope, d()->qmlContext);
2261 QQmlComponentPrivate::setInitialProperties(
2262 v4, qmlCtxt, obj, d()->valuemapOrObject, requiredProperties, o,
2263 QQmlIncubatorPrivate::get(d()->incubator)->creator.data());
2269 QV4::Scope scope(engine());
2271 QObject *object = d()->incubator->object();
2273 if (s == QQmlIncubator::Ready) {
2276 d()->valuemapOrObject.set(scope.engine, QV4::QObjectWrapper::wrap(scope.engine, object));
2278 QQmlData *ddata = QQmlData::get(object);
2280 ddata->explicitIndestructibleSet =
false;
2281 ddata->indestructible =
false;
2284 QV4::ScopedFunctionObject f(scope, d()->statusChanged);
2286 QV4::JSCallArguments jsCallData(scope, 1);
2287 *jsCallData.thisObject =
this;
2288 jsCallData.args[0] = QV4::Value::fromUInt32(s);
2289 f->call(jsCallData);
2290 if (scope.hasException()) {
2291 QQmlError error = scope.engine->catchExceptionAsQmlError();
2292 QQmlEnginePrivate::warning(QQmlEnginePrivate::get(scope.engine->qmlEngine()), error);
2296 if (s != QQmlIncubator::Loading)
2297 d()->incubator->incubatorObject.clear();
2300#undef INITIALPROPERTIES_SOURCE
2304#include "moc_qqmlcomponent.cpp"
2305#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)