diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-03-23 13:03:06 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-03-24 13:27:48 +0000 |
commit | aac1e246e46ab6ea70c14a61b1340d529763787d (patch) | |
tree | 51e891613536ad8a0a92af619b266678aa4c4ddb /src/quicktemplates2/qquickstackview_p.cpp | |
parent | 762d4ceb5fe19d97bcdbdba1dae74816126b7b75 (diff) |
StackView: provide better warnings and errors
Check for valid URLs and test object types. Throw warnings when
appropriate instead of crashing later.
Task-number: QTBUG-59634
Change-Id: Ia269dc8afd31b618f1ff7aec94d684029cb78244
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickstackview_p.cpp')
-rw-r--r-- | src/quicktemplates2/qquickstackview_p.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/quicktemplates2/qquickstackview_p.cpp b/src/quicktemplates2/qquickstackview_p.cpp index 077c13e3..c6f9291d 100644 --- a/src/quicktemplates2/qquickstackview_p.cpp +++ b/src/quicktemplates2/qquickstackview_p.cpp @@ -90,7 +90,7 @@ static bool initProperties(QQuickStackElement *element, const QV4::Value &props, return false; } -QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(QQmlV4Function *args, int from) +QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(int from, QQmlV4Function *args, QStringList *errors) { QV4::ExecutionEngine *v4 = args->v4engine(); QV4::Scope scope(v4); @@ -103,8 +103,9 @@ QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(QQmlV4Function if (QV4::ArrayObject *array = arg->as<QV4::ArrayObject>()) { int len = array->getLength(); for (int j = 0; j < len; ++j) { + QString error; QV4::ScopedValue value(scope, array->getIndexed(j)); - QQuickStackElement *element = createElement(value); + QQuickStackElement *element = createElement(value, &error); if (element) { if (j < len - 1) { QV4::ScopedValue props(scope, array->getIndexed(j + 1)); @@ -112,10 +113,13 @@ QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(QQmlV4Function ++j; } elements += element; + } else if (!error.isEmpty()) { + *errors += error; } } } else { - QQuickStackElement *element = createElement(arg); + QString error; + QQuickStackElement *element = createElement(arg, &error); if (element) { if (i < argc - 1) { QV4::ScopedValue props(scope, (*args)[i + 1]); @@ -123,6 +127,8 @@ QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(QQmlV4Function ++i; } elements += element; + } else if (!error.isEmpty()) { + *errors += error; } } } @@ -147,13 +153,13 @@ QQuickStackElement *QQuickStackViewPrivate::findElement(const QV4::Value &value) return nullptr; } -QQuickStackElement *QQuickStackViewPrivate::createElement(const QV4::Value &value) +QQuickStackElement *QQuickStackViewPrivate::createElement(const QV4::Value &value, QString *error) { Q_Q(QQuickStackView); if (const QV4::String *s = value.as<QV4::String>()) - return QQuickStackElement::fromString(s->toQString(), q); + return QQuickStackElement::fromString(s->toQString(), q, error); if (const QV4::QObjectWrapper *o = value.as<QV4::QObjectWrapper>()) - return QQuickStackElement::fromObject(o->object(), q); + return QQuickStackElement::fromObject(o->object(), q, error); return nullptr; } |