Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED]QDoubleValidator and QLocale()
-
Hi!
I'm trying to use QDoubleValidator for QLineEdit. The proplem is that it let me enter ",", but when I use .To Double() it returns false, cause it can't convert it to double. It can convert it to double only when I use ".", but QDoubleValidator doesn't let me enter it as I said. I decided that the problem is in QLocale and I have to set it for the current system language. I did it, but the situation didn't change. Here is my code.
@QLineEdit* editor=new QLineEdit(parent);
QDoubleValidator *validator=new QDoubleValidator(0,std::numeric_limits<double>::max(),2,editor);
validator->setLocale(QLocale::system());
validator->setNotation(QDoubleValidator::StandardNotation);
editor->setValidator(validator);
return editor;@
-
Use this one
editor->text().replace(",","").toDouble();
-
Thanx a lot!It worked=)