Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.5.1
-
None
Description
QComboBox tends to send incorrect index and string in its activated() signal when it was set with QCompleter, which in turn is initialized with model other than the one of in QComboBox.
The reproducing application is the same as for QTBUG-51858:
// main.cpp #include <QApplication> #include "form.h" int main(int argc, char** argv) { QApplication app(argc, argv); Form form; form.show(); return app.exec(); } // form.h #ifndef FORM_H #define FORM_H #include <QWidget> class QSortFilterProxyModel; class Form : public QWidget { Q_OBJECT public: Form(); private slots: void test_activated(int index); void edit_text_changed(QString text); private: QSortFilterProxyModel* m_filteredModel; }; #endif // FORM_H // form.cpp #include "form.h" #include <QDebug> #include <QComboBox> #include <QCompleter> #include <QSortFilterProxyModel> Form::Form() { resize(200, 50); QComboBox* p = new QComboBox(this); p->setEditable(true); p->setCompleter(new QCompleter(p)); p->completer()->setCaseSensitivity(Qt::CaseInsensitive); p->setInsertPolicy(QComboBox::NoInsert); connect(p, SIGNAL(activated(int)), this, SLOT(test_activated(int))); m_filteredModel = new QSortFilterProxyModel(this); m_filteredModel->setFilterCaseSensitivity(Qt::CaseInsensitive); m_filteredModel->setSourceModel(p->model()); connect(p, SIGNAL(editTextChanged(QString)), this, SLOT(edit_text_changed(QString))); p->completer()->setCompletionMode(QCompleter::UnfilteredPopupCompletion); p->completer()->setModel(m_filteredModel); QStringList items; items << "" << "Hello" << "Hair" << "World"; p->addItems(items); } void Form::test_activated(int index) { qDebug() << "Form::test_activated, index:" << index; } void Form::edit_text_changed(QString text) { m_filteredModel->setFilterFixedString(text); }