Beginner question: forcing comma into point
-
Hello,
how can I force LineEdit to replace comma into point?
I have to want make a little calculate-similar tool.@
double value =
ui->lineEdit->text().toDouble(); // for Example: value is: 500 comma 32calculateProcess() .....
backCasting()....
@So I want to force lineEdit to casting the comma to point automaticly. How can I do that?
I cant use this:
@
QLocale current(QLocale("de_DE"));
current.setNumberOptions(QLocale::c().numberOptions());
QLocale::setDefault(current);
@because I got diverse error-message :(
-
Hi,
You can subclass a "QValidator":http://qt-project.org/doc/qt-5.1/qtgui/qvalidator.html and implement the validate() method to do whatever string transformations you need. Then just set it on the QLineEdit with "setValidator()":http://qt-project.org/doc/qt-5.1/qtwidgets/qlineedit.html#setValidator -
[quote author="Rutschuru" date="1386515682"]
because I got diverse error-message :([/quote]
What kind of error messages?See "this":http://qt-project.org/doc/qt-4.8/qlocale.html#toDouble.
Also see QLocale::decimalPoint() and QLocale::groupSeparator() and make sure you have set the QLocale on the line edit.