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

QDoubleValidator does not accept '.' as decimal

XMLWordPrintable

    • 445ef8847979dab72893aab1924d46d0fe1a8a3e

      This is a regression from Qt 4.6.3. The change in QTBUG-3179 seems to be what broke this.

      The documentation for QDoubleValidator says:

      "In addition, QDoubleValidator is always guaranteed to accept a number formatted according to the "C" locale."

      So a string "0.2" should always be accepted, since it is OK according the "C" locale, but QDoubleValidator does not return Accepted for QLocale::German.

      The following example reproduces the problem:

      QDoubleValidator::State state;
      int pos = 0;
      QDoubleValidator v(0.0,1.0,2,0);
      QString input1 = "0.2";
      v.setLocale(QLocale::C);
      state = v.validate ( input1, pos ); // State is accepted, correct!
      v.setLocale(QLocale::German);
      state = v.validate ( input1, pos ); // state is not accepted but intermediate !!!!
      

      The following example reproduces the problem:

      #include <QtGui>
      
      int main(int argc, char** argv)
      {
      	QApplication app(argc, argv);
      	int pos = 0;
      	QLocale::setDefault(QLocale::C);
      	qDebug() << "QValidator::Acceptable" << QDoubleValidator(0.0, 1.0, 5, 0).validate(QString("0.31"), pos); // 4.6.3 acceptable, 4.7.0 acceptable
      	// changed from invalid to intermediate in 4.7.0
      	qDebug() << "QValidator::Intermediate" << QDoubleValidator(0.0, 1.0, 5, 0).validate(QString("0,31"), pos); // 4.6.3 invalid, 4.7.0 intermediate
      	QLocale::setDefault(QLocale::German);
      	// changed from acceptable to intermediate in 4.7.0. This is a killer !!!
      	qDebug() << "QValidator::Intermediate" << QDoubleValidator(0.0, 1.0, 5, 0).validate(QString("0.31"), pos); // 4.6.3 acceptable, 4.7.0 intermediate
      	qDebug() << "QValidator::Acceptable" << QDoubleValidator(0.0, 1.0, 5, 0).validate(QString("0,31"), pos); // 4.6.3 acceptable, 4.7.0 acceptable
      	return app.exec();
      
      }

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

            dedietri Gabriel de Dietrich (drgvond)
            naevdal Sigrid Fjell Nævdal (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes