Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]QDoubleValidator and QLocale()
QtWS25 Last Chance

[SOLVED]QDoubleValidator and QLocale()

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Polina89
    wrote on last edited by
    #1

    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;@

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TITU87
      wrote on last edited by
      #2

      Use this one
      editor->text().replace(",","").toDouble();

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Polina89
        wrote on last edited by
        #3

        Thanx a lot!It worked=)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved