PDA

View Full Version : Behavior not expected by QDoubleValidator()



vcp
1st February 2011, 19:27
Hi people,

I noticed recently that there is a problem with QDoubleValidator (), which didn't happen when I used the QT 4.6.x.
Even defining the validation, for example, two decimal places the QLineEdit supports typing in more decimal places than it was defined.
The QLineEdit was created without any special parameters set.


leNUMBER-> setValidator (new QDoubleValidator (0.0,999999999.99,2, leNUMBER));


I can enter the field, for example, 123.4567895555555.

The funny thing is, as I said, the behavior prior to version 4.7.x
wasn't to allow more informed than the decimal places, which is correct.

If anyone has any suggestion for me I would be very grateful.

Zlatomir
1st February 2011, 20:08
That is because the scientific notation, use something like this:


QLineEdit *le = new QLineEdit;
QDoubleValidator *validator = new QDoubleValidator (0.0, 99.99, 2, le);
validator->setNotation(QDoubleValidator::StandardNotation);
le->setValidator(validator);

vcp
2nd February 2011, 10:47
Zlatomir Hi,

I followed your example and it works, but there is a strange behavior that
I would like (if you can) explain.

If I set the maximum value 99.99 as I type up to 99. and not allowed to enter after the decimal point.
If I set the maximum value to 999.99 I can only enter values this way: 999. or 89.9 or .99.
That is, before the decimal point three digits can not exist for the value after the point decimail.
If the value in less than three digits to get the point and only one digit after.
If I place a value less than 1 (eg .50) QLineEdit does not allow me to put anything on the field.

In short, I can not type for example: 999.99 486.88 15.66 1:55 1:00 properly, as happened before.

With higher values the deal gets even crazier still:
If I define as the maximum 999999999.99 see what happens:

Case 1: Only allow enter up to 999999999. (does not allow decimal places)
Case 2: If I enter values less than the maximum allowed it lets you enter more than the number of homes decimail defined: Ex: 156.6666666

Super weird!

Thanks in advance.

Zlatomir
2nd February 2011, 11:35
This behavior i can't replicate, i wrote this simple example:

#include <QtGui>

int main(int argc, char** argv){
QApplication a(argc, argv);
QLineEdit *le = new QLineEdit(0);

QDoubleValidator *validator = new QDoubleValidator (0.0, 999999999.99, 2, le);
validator->setNotation(QDoubleValidator::StandardNotation);
le->setValidator(validator);
le->show();
int ret = a.exec();
delete le;
return ret;
}
And it works on my machine with both 99.99 and 999999999.99
LE: i use Qt SDK tech preview on Windows.

vcp
2nd February 2011, 12:32
Thanks for while,

I use Qt SDK 2010.05 on windows and native fedora 14 (32bits) qt 4.7.1
in both the problem happens.:(

Exists a information of bug in qt bug tracker about this: see [QTBUG-14852]

Zlatomir
2nd February 2011, 13:36
It doesn't look like the same bug to me.
Maybe the one you have it was fixed in the newer builds (because on my machine as i said i have the Tech Preview)
I'll try with Qt SDK 2010.05 on kubuntu, but later this evening.

vcp
2nd February 2011, 16:34
Ok, I'm waiting for your test.
I tried various approaches so far, but nothing
doing the same effect as before.
This is a big problem.

Zlatomir
2nd February 2011, 18:51
I can't replicate your problem, tried the example i posted earlier with: Qt SDK 2010.05 on Kubuntu and Qt 4.7.0 integrated in VS 2008 (Win 7).

vcp
3rd February 2011, 11:15
Hi,

Well. That's it!

I installed the SDK 2010.03 Qt (Qt 4.6.3) and QDoubleValidator had expected behavior.
That is, regarding the number of decimals and format type.
If I enter a range from 0.0 to 999999999.99 eg,
typing occurs as expected. Allowing values enter the range and informed typing correct format.

Well, now is the problem and the question: What to do?