Utils: Do not crash when clicking in empty line of HistoryCompleter

Removing lines from a HistoryCompleter can result in a crash if the
mouse click happens on an empty line.

Change-Id: I02ee7c4705e1a4bc6b63ccdae207b5078b03360e
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Stenger
2018-12-03 09:35:44 +01:00
parent b79c0628e5
commit 3a4a53ee1c

View File

@@ -117,8 +117,11 @@ private:
if (layoutDirection() == Qt::LeftToRight)
rr = viewport()->width() - event->x();
if (rr < clearButtonSize.width()) {
model->removeRow(indexAt(event->pos()).row());
return;
const QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
model->removeRow(indexAt(event->pos()).row());
return;
}
}
}
QListView::mousePressEvent(event);