Please nominate your Qt Champions for 2021!

Double not recognized

  • Hi,

    I have a strange thing:
    In my country, the decimal separator is 'a comma.

    In a line edit with a QDoubleValidator I enter 1,5
    but if i do
    bool bIsOk = false;
    double dValue = <my lineEdit>->text().toDouble(&bIsOk);

    bIsOk is still false.
    Why ? because QDoubleValidator accepts my string.


  • Moderators



    have a look at the docu QLocale::toDouble should solve your , seperator problem :)

  • double dValue =<my lineEdit>->locale().toDouble(<my lineEdit>->text());

    on the other hand, QLineEdit + QDoubleValidator = QDoubleSpinBox + QDoubleSpinBox::setButtonSymbols(QAbstractSpinBox::NoButtons)
    and you can use QDoubleSpinBox::value to get the value directly in decimal

Log in to reply