DesignIsLife
DesignIsLife

Reputation: 530

QDoubleValidator 's validate() not working?

I don't want to validate the double Value Using QLineEdit, I want to validate it from the code itself, so I tried :

QDoubleValidator dv(1.5,30.0,1);
double d = 1.3;
int pos=0;
qDebug()<< dv.validate(QString::number(d,'f',1), pos);

This Above qDebug() should return QValidator::Invalid i.e. 0, But it is returning QValidator::Intermediate i.e. 1 always for every double value ?

Upvotes: 2

Views: 1370

Answers (1)

vahancho
vahancho

Reputation: 21220

According to the Qt source code, it will return QValidator::Invalid only if:

  • The input does not represent double value,
  • The value contains '-' sign, indicating that it is negative value, but bottom value is not negative,
  • Input string does not end with '\0'.

It will return QValidator::Acceptable only if input string represents a valid double value (excluding mentioned above) that falls between bottom and top values.

All the rest cases the function returns QValidator::Intermediate.

Upvotes: 3

Related Questions