QDoubleValidator is not working?

user987013 picture user987013 · Apr 12, 2012 · Viewed 16.8k times · Source

I'm trying to apply validator in a line edit box in Qt 4.2 and it is not working:

 QDoubleValidator *haha= new QDoubleValidator(this);
 haha->setBottom(0.00);
 haha->setDecimals(2);
 haha->setTop(100.00); 
 get_line_edit()->setValidator(haha);

or

 QDoubleValidator *haha= new QDoubleValidator(0.00,100.00,2,this);

Neither way, I can still enter what ever value I want.

But if I switch to QIntValidator, it works!

So I went onto Google and did a bit search, and many people used to having the same issue. Is it a bug? or there should be some other set up I should do?

Answer

soulia picture soulia · Oct 10, 2014

Just tripped over this one. Try setting the QDoubleValidator notation to:

doubleValidator->setNotation(QDoubleValidator::StandardNotation);