aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlcomponent_p.h
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-06-14 10:35:42 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2022-06-30 20:26:21 +0200
commit79f9e22ef7e18af289457c0c4030f1e2af870213 (patch)
treed95e9973401e5bfc0c8328050afe3576bdd321a2 /src/qml/qml/qqmlcomponent_p.h
parentd968b23671d596d3502555f41feb38d046cb6414 (diff)
Do not store instantiation errors in QQmlComponent
QQmlComponent::createWithInitialProperties() allows to pass non-existent properties to create the object with. In this case, we still return a valid pointer (pre-existing), however, the state of the component is affected: there are errors internally that fail repeated calls even with valid properties specified. Fix this, aligning to the behavior of QQmlComponent::createObject() which is a QML counterpart of the same function (to a degree) Additionally, make required properties warnings also not break the component state: if a required property is not set, we return nullptr instead of object. The error state is affected but it gets cleaned on the next creation call, allowing one to set the missing required properties Unify the logic (with slight deviations) between create() (the non-incubator-accepting version), createWithInitialProperties() and createObject() as all they all should do roughly equivalent things [ChangeLog][QQmlComponent][Important Behavior Changes] Setting properties via createWithInitialProperties() and setInitialProperties() no longer affects the QQmlComponent's error state unless there are unset required properties. A warning is issued when a property could not be set. Fixes: QTBUG-101439 Change-Id: I814c00bc3715d7a54004c3fcd0af6ee6d50b0726 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlcomponent_p.h')
-rw-r--r--src/qml/qml/qqmlcomponent_p.h30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlcomponent_p.h b/src/qml/qml/qqmlcomponent_p.h
index 3edd330ee8..d4a1e10f12 100644
--- a/src/qml/qml/qqmlcomponent_p.h
+++ b/src/qml/qml/qqmlcomponent_p.h
@@ -75,10 +75,31 @@ public:
bool hadTopLevelRequiredProperties() const;
QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit;
+ struct AnnotatedQmlError
+ {
+ AnnotatedQmlError() = default;
+ AnnotatedQmlError(const QQmlError &error) // convenience ctor
+ : error(error)
+ {
+ }
+ AnnotatedQmlError(const QQmlError &error, bool transient)
+ : error(error), isTransient(transient)
+ {
+ }
+ QQmlError error;
+ bool isTransient = false; // tells if the error is temporary (e.g. unset required property)
+ };
+
struct ConstructionState {
std::unique_ptr<QQmlObjectCreator> creator;
- QList<QQmlError> errors;
+ QList<AnnotatedQmlError> errors;
bool completePending = false;
+
+ void appendErrors(const QList<QQmlError> &qmlErrors)
+ {
+ for (const QQmlError &e : qmlErrors)
+ errors.emplaceBack(e);
+ }
};
ConstructionState state;
@@ -103,6 +124,13 @@ public:
QObject *doBeginCreate(QQmlComponent *q, QQmlContext *context);
bool setInitialProperty(QObject *component, const QString &name, const QVariant& value);
+ enum CreateBehavior {
+ CreateDefault,
+ CreateWarnAboutRequiredProperties,
+ };
+ QObject *createWithProperties(QObject *parent, const QVariantMap &properties,
+ QQmlContext *context, CreateBehavior behavior = CreateDefault);
+
bool isBound() const {
return compilationUnit->unitData()->flags & QV4::CompiledData::Unit::ComponentsBound;
}