diff options
author | jasplin <qt-info@nokia.com> | 2009-03-25 13:45:55 (GMT) |
---|---|---|
committer | jasplin <qt-info@nokia.com> | 2009-03-25 13:50:57 (GMT) |
commit | a794ded85f74516239a08cf848e6b4f8b6dcac6a (patch) | |
tree | fd8b1df57116bd1f508c48d03bba44725d8e99ce | |
parent | 35528b2109db5832cbd0a4fcde6e6cd1f5bdd6db (diff) | |
download | Qt-a794ded85f74516239a08cf848e6b4f8b6dcac6a.zip Qt-a794ded85f74516239a08cf848e6b4f8b6dcac6a.tar.gz Qt-a794ded85f74516239a08cf848e6b4f8b6dcac6a.tar.bz2 |
Fix assertion failure in QCompleter::setCompletionPrefix().
Calling setCompletionPrefix() on a QCompleter from a slot connected
to the editingFinished() signal of the corresponding QLineEdit
could in some cases alter the internal state of the completer in
such a way that an assertion would fail. The fix prevents the
asserting code from being called in this particular state.
Reviewed-by: janarve
Task-number: 246056
-rw-r--r-- | src/gui/util/qcompleter.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qcompleter/tst_qcompleter.cpp | 33 |
2 files changed, 35 insertions, 2 deletions
diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp index 8b07163..aeb7e91 100644 --- a/src/gui/util/qcompleter.cpp +++ b/src/gui/util/qcompleter.cpp @@ -824,9 +824,9 @@ void QCompleterPrivate::_q_complete(QModelIndex index, bool highlighted) Q_Q(QCompleter); QString completion; - if (!index.isValid()) + if (!index.isValid() || (index.row() >= proxy->engine->matchCount())) { completion = prefix; - else { + } else { QModelIndex si = proxy->mapToSource(index); si = si.sibling(si.row(), column); // for clicked() completion = q->pathFromIndex(si); diff --git a/tests/auto/qcompleter/tst_qcompleter.cpp b/tests/auto/qcompleter/tst_qcompleter.cpp index 6434d49..67b9b67 100644 --- a/tests/auto/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/qcompleter/tst_qcompleter.cpp @@ -140,6 +140,7 @@ private slots: // task-specific tests below me void task178797_activatedOnReturn(); void task189564_omitNonSelectableItems(); + void task246056_setCompletionPrefix(); private: void filter(); @@ -1093,5 +1094,37 @@ void tst_QCompleter::task189564_omitNonSelectableItems() QVERIFY(matches2.isEmpty()); } +class task246056_ComboBox : public QComboBox +{ + Q_OBJECT +public: + task246056_ComboBox() + { + setEditable(true); + setInsertPolicy(NoInsert); + Q_ASSERT(completer()); + completer()->setCompletionMode(QCompleter::PopupCompletion); + completer()->setCompletionRole(Qt::DisplayRole); + connect(lineEdit(), SIGNAL(editingFinished()), SLOT(setCompletionPrefix())); + } +private slots: + void setCompletionPrefix() { completer()->setCompletionPrefix(lineEdit()->text()); } +}; + +void tst_QCompleter::task246056_setCompletionPrefix() +{ + task246056_ComboBox *comboBox = new task246056_ComboBox; + comboBox->addItem(""); + comboBox->addItem("a1"); + comboBox->addItem("a2"); + comboBox->show(); + comboBox->setFocus(); + QTest::qWait(100); + 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! +} + QTEST_MAIN(tst_QCompleter) #include "tst_qcompleter.moc" |