Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-51889

QCompleter makes parent QComboBox to call activated() signal twice

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.5.1
    • None

    Description

      Usage of QComplete with PopupCompletion completion mode leads to duplicate calling of activated() signal in parent QComboBox widget, when user chooses an auto-complete option in popup list and not in QComboBox itself.

      Here's a minimal reproducing code:

      //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 Form : public QWidget
      {
      Q_OBJECT
      
      public:
      	Form();
      
      private slots:
      	void test_activated(int index);
      };
      
      #endif // FORM_H
      
      // form.cpp
      
      #include "form.h"
      
      #include <QDebug>
      
      #include <QComboBox>
      #include <QCompleter>
      
      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)));
      
      	p->completer()->setCompletionMode(QCompleter::PopupCompletion);
      	p->completer()->setModel(p->model());
      
      	QStringList items;
      	items << "" << "Hello" << "Hair" << "World";
      	p->addItems(items);
      }
      
      void Form::test_activated(int index)
      {
      	qDebug() << "Form::test_activated, index:" << index;
      }
      
      

      To reproduce:
      1. Type "H" and choose any completion variant with down arrow and Enter.
      2. Notice something like:

      Form::test_activated, index: 1
      Form::test_activated, index: 1
      

      appearing at once in the output.

      Attachments

        For Gerrit Dashboard: QTBUG-51889
        # Subject Branch Project Status CR V

        Activity

          People

            peppe Giuseppe D'Angelo
            achernov Alexey Chernov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change