diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp index 64b7b12e90..18c8ed2bd2 100644 --- a/src/widgets/util/qcompleter.cpp +++ b/src/widgets/util/qcompleter.cpp @@ -829,6 +829,7 @@ void QCompleterPrivate::_q_complete(QModelIndex index, bool highlighted) if (!index.isValid() || (!proxy->showAll && (index.row() >= proxy->engine->matchCount()))) { completion = prefix; + index = QModelIndex(); } else { if (!(index.flags() & Qt::ItemIsEnabled)) return; diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp index 0f7993540c..3a6fca7146 100644 --- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp @@ -1305,10 +1305,15 @@ void tst_QCompleter::task246056_setCompletionPrefix() comboBox.show(); QApplication::setActiveWindow(&comboBox); QVERIFY(QTest::qWaitForWindowActive(&comboBox)); + QSignalSpy spy(comboBox.completer(), SIGNAL(activated(QModelIndex))); QTest::keyPress(&comboBox, 'a'); QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Down); QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Down); QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Enter); // don't crash! + QCOMPARE(spy.count(), 1); + QList arguments = spy.at(0); + QModelIndex index = arguments.at(0).value(); + QVERIFY(!index.isValid()); } class task250064_TextEdit : public QTextEdit