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

textEdited() signal is not sent if QValidator used

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4: Low P4: Low
    • None
    • 5.4.0
    • None
    • Windows 7

      Test the following code. Start typing to the upper textfield which uses own QValidator where text is changed to upper letters. textEdited() signal is not sent if validator changes the text.
      http://qt-project.org/doc/qt-4.8/qlineedit.html#textEdited
      This worked in Qt4.8 but not in Qt5.4

      #include <QMainWindow>
      #include <QWidget>
      #include <QVBoxLayout>
      #include <QLineEdit>
      #include <QApplication>
      #include <QDebug>
      #include <QRegExp>
      #include <QRegExpValidator>
      
      class MyValidator : public QValidator
      {
          Q_OBJECT
      
      public :
          MyValidator(QObject *parent = 0) : QValidator(parent)
          {
          }
      
      public slots :
          State validate(QString &input, int &) const
          {
              input = input.toUpper() ;
              return(Acceptable) ;
          }
      } ;
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public :
          MainWindow(QWidget *parent = 0) : QMainWindow(parent)
          {
              QWidget     *w  ;
              QVBoxLayout *lo ;
              QLineEdit   *le ;
              MyValidator  *myValidator ;
              QRegExpValidator *va2;
      
              w  = new QWidget ;
              lo = new QVBoxLayout ;
      
              le = new QLineEdit(this) ;
              lo->addWidget(le) ;
      
              myValidator = new MyValidator(le) ;
              le->setValidator(myValidator) ;
      
              this->connect(le, SIGNAL(textEdited(const QString &)), SLOT(le_edited(const QString &))) ;
              this->connect(le, SIGNAL(textChanged(const QString &)), SLOT(le_changed(const QString &))) ;
      
              le = new QLineEdit(this) ;
              lo->addWidget(le) ;
      
      
              QRegExp rx("-?\\d{1,3}");
      
              va2 = new QRegExpValidator(rx, le);
      
              le->setValidator(va2);
      
      
              this->connect(le, SIGNAL(textEdited(const QString &)), SLOT(le_edited(const QString &))) ;
              this->connect(le, SIGNAL(textChanged(const QString &)), SLOT(le_changed(const QString &))) ;
      
              w->setLayout(lo) ;
              this->setCentralWidget(w) ;
          }
      
      private slots :
          void le_edited(const QString &line)
          {
              qDebug() << __LINE__ << line << "edited" ;
          }
      
          void le_changed(const QString &line)
          {
              qDebug() << __LINE__ << line << "changed" ;
          }
      } ;
      
      #include "main.moc"
      
      int main(int argc, char **argv)
      {
          QApplication a(argc, argv);
          MainWindow w;
          w.show();
          return a.exec();
      }
      

        1. qtbug44046_diag.diff
          2 kB
          Friedemann Kleint
        2. qtbug44046_log.txt
          0.6 kB
          Friedemann Kleint
        3. QTBUG-44046.zip
          1 kB
          Qt Support
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            qtcomsupport Qt Support
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes