Important: Please read the Qt Code of Conduct -

[Solved]QDoubleValidator: How to reject comma as decimal point?

  • Hi,

    in my application I want to avoid that numbers are entered with a comma as decimal point.

    code for the validator:
    QDoubleValidator v;
    QLocale loc=QLocale::c();
    loc.setNumberOptions(QLocale::RejectGroupSeparator | QLocale::OmitGroupSeparator);

    The problem is that the validator accepts both "1.23" and "1,23".

    Am I doing sth wrong or might this be a bug in Qt?

    I'm using Qt 4.8.4.

  • I know that is a late answer, but will be usefull for someone with the same need.
    i resolve with QRegExpValidator
    lineEdit->setValidator(new QRegExpValidator(QRegExp("[-]{0,1}\d{0,}\.\d{0,}"),0) );
    it work for me, only accept one dot.

  • I solved it with QRegExpValidator, too.

    Here's my version:
    @QRegExpValidator validator=new QRegExpValidator(QRegExp("^\-?\d\.?\d*(e\-?\d*)?$", Qt::CaseInsensitive),parent);

Log in to reply