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

QLineEdit::text() misleads the user

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.6.2
    • None
    • CentOS Release 6.5 (Final) GNU/Linux Kernel 2.6.32-431.1.2.0.1.el6.i686

    Description

      Assume the code, intended to ask user for 4-digit hexadecimal number using tne input mask for user's convenience:

      #include <QApplication>
      
      #include <QHBoxLayout>
      
      #include <QWidget>
      #include <QLineEdit>
      #include <QPushButton>
      
      
      #include <QtDebug>
      
      
      class Form: public QWidget
      {
          Q_OBJECT
      public:
      
          Form(QWidget* parent=0):
              QWidget(parent),
              _line_edit(new QLineEdit(this)),
              _push_button(new QPushButton("check", this))
          {
              new QHBoxLayout(this);
      
              layout()->addWidget(_line_edit);
              layout()->addWidget(_push_button);
      
              _line_edit->setInputMask("\\0\\xHHHH;0");
      
              connect(_push_button, SIGNAL(clicked(bool)), this, SLOT(check()));
          }
      
      private slots:
      
          void check()
          {
              qDebug()
                  << "text():" << _line_edit->text()
                  << "displayText():" << _line_edit->displayText();
          }
      
      private:
          QLineEdit* _line_edit;
          QPushButton* _push_button;
      };
      
      
      int main(int argc, char* argv[])
      {
          QApplication app(argc, argv);
      
          Form form;
      
          form.show();
      
          return app.exec();
      }
      
      
      #include "main.moc"
      

      Let's input the number 0x2014 in the line edit widget and click "check" button. Oh, the result is:

      text(): "0x214" displayText(): "0x2014"

      But the user is sure, he (or she) typed the value 0x2014!

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            peppe Giuseppe D'Angelo
            slava_phirsov phirsov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes