Item widgets: fix crash in mimeTypes()

*Always* check the result of a dynamic/qobject cast. I'm not positive
if the cast is correct (or should it just be a static cast),
but in principle these models can be used with a different view.

Change-Id: I37108cbb2744b6bf0fb46392d1cc9883f2d0b60e
Pick-to: 5.15
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
bb10
Giuseppe D'Angelo 2020-07-07 13:54:49 +02:00
parent 26eb4e63e0
commit 8a78830b0d
2 changed files with 7 additions and 2 deletions

View File

@ -463,7 +463,9 @@ void QListModel::itemChanged(QListWidgetItem *item, const QList<int> &roles)
QStringList QListModel::mimeTypes() const
{
const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent());
return view->mimeTypes();
if (view)
return view->mimeTypes();
return {};
}
QMimeData *QListModel::internalMimeData() const

View File

@ -738,7 +738,10 @@ QList<QTreeWidgetItem*>::iterator QTreeModel::sortedInsertionIterator(
QStringList QTreeModel::mimeTypes() const
{
return view()->mimeTypes();
auto v = view();
if (v)
return v->mimeTypes();
return {};
}
QMimeData *QTreeModel::internalMimeData() const