diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-10 11:37:59 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-10 15:53:36 +0200 |
commit | 6fceeab1d15e1d6c1fa3d8e067f2acdeccb78e64 (patch) | |
tree | 112366fdd8d898d57cf3dd0fcb7d868b5b179d33 /tests | |
parent | cb9bfcd5c0a8bf541d3b67a80ca22ed11662b422 (diff) |
QML ListModel: Emit a warning when adding an object with undefined or null member
The current code in ListModel simply did a reset of an existing
property, in case a role existed and was set to null/undefined. If the
role did not exist, the code would simply skip over the member and do
nothing.
However, this does not make any sense for newly inserted items, and
most likely indicates a misunderstanding of how ListModel works.
Creating an undefined/null role does not really make sense, as those
could only ever store a undefined/null value.
Change-Id: I4c1361647a82146565eaffe064598c94c748b4f5
Task-number: QTBUG-63569
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp index b47062ee94..75a932b6f4 100644 --- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp +++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp @@ -129,6 +129,7 @@ private slots: void crash_append_empty_array(); void dynamic_roles_crash_QTBUG_38907(); void nestedListModelIteration(); + void undefinedAppendShouldCauseError(); }; bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object) @@ -1694,6 +1695,35 @@ void tst_qqmllistmodel::nestedListModelIteration() QScopedPointer<QObject>(component.create()); } +// QTBUG-63569 +void tst_qqmllistmodel::undefinedAppendShouldCauseError() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData( + R"(import QtQuick 2.5 + Item { + width: 640 + height: 480 + ListModel { + id : model + } + Component.onCompleted: { + var tempData = { + faulty: undefined + } + model.insert(0, tempData) + tempData.faulty = null + model.insert(0, tempData) + } + })", + QUrl()); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "<Unknown File>: faulty is undefined. Adding an object with a undefined member does not create a role for it."); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "<Unknown File>: faulty is null. Adding an object with a null member does not create a role for it."); + QScopedPointer<QObject>(component.create()); +} + + QTEST_MAIN(tst_qqmllistmodel) #include "tst_qqmllistmodel.moc" |