From 3a4a53ee1cfe595f959e9bcc90beb760db980533 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 3 Dec 2018 09:35:44 +0100 Subject: [PATCH] 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 --- src/libs/utils/historycompleter.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/historycompleter.cpp b/src/libs/utils/historycompleter.cpp index 8657374f776..fa037ddd612 100644 --- a/src/libs/utils/historycompleter.cpp +++ b/src/libs/utils/historycompleter.cpp @@ -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);