diff options
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 6 | ||||
-rw-r--r-- | tests/auto/quick/qquicklistview/data/usechooserwithoutdefault.qml | 63 | ||||
-rw-r--r-- | tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | 11 |
3 files changed, 77 insertions, 3 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 6732be9844..015458169a 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1049,16 +1049,16 @@ QObject *QQmlDelegateModelPrivate::object(Compositor::Group group, int index, QQ cacheItem->incubationTask->forceCompletion(); } } else if (!cacheItem->object) { - QQmlComponent *delegate = nullptr; + QQmlComponent *delegate = m_delegate; if (m_delegateChooser) { QQmlAbstractDelegateComponent *chooser = m_delegateChooser; do { delegate = chooser->delegate(&m_adaptorModel, index); chooser = qobject_cast<QQmlAbstractDelegateComponent *>(delegate); } while (chooser); + if (!delegate) + return nullptr; } - if (!delegate) - delegate = m_delegate; QQmlContext *creationContext = delegate->creationContext(); diff --git a/tests/auto/quick/qquicklistview/data/usechooserwithoutdefault.qml b/tests/auto/quick/qquicklistview/data/usechooserwithoutdefault.qml new file mode 100644 index 0000000000..45164222f2 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/usechooserwithoutdefault.qml @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Window 2.3 +import Qt.labs.qmlmodels 1.0 + +Item { + width: 640 + height: 450 + + ListView { + width: 600 + height: 400 + model: 2 + delegate: DelegateChooser { + DelegateChoice { + index: 0 + delegate: Rectangle { + width: 100 + height: 100 + color:"green" + } + } + } + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 9c11957894..1ca341fe66 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -267,6 +267,8 @@ private slots: void QTBUG_34576_velocityZero(); void QTBUG_61537_modelChangesAsync(); + void useDelegateChooserWithoutDefault(); + void addOnCompleted(); private: @@ -8858,6 +8860,15 @@ void tst_QQuickListView::addOnCompleted() } } +void tst_QQuickListView::useDelegateChooserWithoutDefault() +{ + // Check that the application doesn't crash + // if the delegate chooser doesn't cover all cells + QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("usechooserwithoutdefault.qml")); + window->show(); +}; + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" |