Fix QCompleter::activated(QModelIndex)

When falling back to the completion prefix, make sure to also pass an
invalid index to activated().

Change-Id: I6b282a01c95492466890632b77837bcc96eb038a
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
This commit is contained in:
J-P Nurmi 2013-08-07 14:23:18 +02:00 committed by The Qt Project
parent e6218ecfb5
commit cffd1633b2
2 changed files with 6 additions and 0 deletions

View File

@ -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;

View File

@ -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<QVariant> arguments = spy.at(0);
QModelIndex index = arguments.at(0).value<QModelIndex>();
QVERIFY(!index.isValid());
}
class task250064_TextEdit : public QTextEdit