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. Double not recognized

Double not recognized

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 707 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.
  • Roy44R Offline
    Roy44R Offline
    Roy44
    wrote on last edited by
    #1

    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.

    thanks

    J.HilkJ 1 Reply Last reply
    0
    • Roy44R Roy44

      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.

      thanks

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by VRonin
      #2

      @Roy44

      hi,

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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      4
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        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

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2

        • Login

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