Validate a QLineEdit to only get Double

1

I'm using QDoubleValidator data = new QDoubleValidator(0.00, 1000.00, 2, lineEdit);

But when you enter the actual value in the lineEdit field, it does not use the dot ( . ) as the decimal separator, and yes comma ( , ).

This causes problems when picking the value typed in the field because the program does not take any numbered value using commas.

How to resolve this problem by leaving the dot ( . ) as the decimal separator?

    
asked by anonymous 30.07.2014 / 21:30

1 answer

1

You need to set locale of QDoubleValidator :

auto validator = new QDoubleValidator(0, 1000.00, 2, lineEdit);
validator->setLocale(QLocale("pt_BR"));
lineEdit->setValidator(validator);

Note that, by default, Qt uses the system locale. If you use the above code to set the locale, your program will no longer conform to user preferences.

    
07.08.2014 / 04:09