Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. This funny decimal point...
Forum Updated to NodeBB v4.3 + New Features

This funny decimal point...

Scheduled Pinned Locked Moved Solved Mobile and Embedded
13 Posts 5 Posters 2.2k Views 2 Watching
  • 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.
  • G Offline
    G Offline
    Gourmet
    wrote on last edited by Gourmet
    #1

    I use QLineEdit to enter some floating point values. To restrict input I set the validator:

    QDoubleValidator* realvalidator;
    realvalidator = new QDoubleValidator(0.0, 1000000.0, 2, this);
    realvalidator->setNotation(QDoubleValidator::StandardNotation);
    ui->lineEdit->setValidator( realvalidator );
    

    as obvious. To show Android digital keyboard I use input method hint:

    ui->lineEdit->setInputMethodHints( Qt::ImhFormattedNumbersOnly );
    

    This shows virtual digital keyboard with button "." for decimal point. But it... does not work cause in my locale the decimal point is ",". Validator ignores this button. Ok, I remove last code line. This forces show alpha-numeric keyboard with "," button. It enters to line and line looks fine... But when I convert data to double value with

    ui->lineEdit->text().toDouble()
    

    I get 0.0 cause "," is not recognizable by toDouble() conversion - this conversion ignores locale. I had write before toDouble() this stupid line to get all temporarily working:

    ui->lineEdit->setText(ui->lineEdit->text().replace(QChar(','),QChar('.')));
    

    This rocks. But now I have TWO decimal points! One for editor and another one for storage. What's a fun... I would limit this only by "." to allow use digital keyboard and convert without stupid code. I tried use

    realvalidator->setLocale(QLocale(QLocale::Arabic));
    

    but this... prohibits input both "," and ".".
    :-()

    Any ideas?

    aha_1980A 1 Reply Last reply
    0
    • G Gourmet

      I use QLineEdit to enter some floating point values. To restrict input I set the validator:

      QDoubleValidator* realvalidator;
      realvalidator = new QDoubleValidator(0.0, 1000000.0, 2, this);
      realvalidator->setNotation(QDoubleValidator::StandardNotation);
      ui->lineEdit->setValidator( realvalidator );
      

      as obvious. To show Android digital keyboard I use input method hint:

      ui->lineEdit->setInputMethodHints( Qt::ImhFormattedNumbersOnly );
      

      This shows virtual digital keyboard with button "." for decimal point. But it... does not work cause in my locale the decimal point is ",". Validator ignores this button. Ok, I remove last code line. This forces show alpha-numeric keyboard with "," button. It enters to line and line looks fine... But when I convert data to double value with

      ui->lineEdit->text().toDouble()
      

      I get 0.0 cause "," is not recognizable by toDouble() conversion - this conversion ignores locale. I had write before toDouble() this stupid line to get all temporarily working:

      ui->lineEdit->setText(ui->lineEdit->text().replace(QChar(','),QChar('.')));
      

      This rocks. But now I have TWO decimal points! One for editor and another one for storage. What's a fun... I would limit this only by "." to allow use digital keyboard and convert without stupid code. I tried use

      realvalidator->setLocale(QLocale(QLocale::Arabic));
      

      but this... prohibits input both "," and ".".
      :-()

      Any ideas?

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Gourmet

      ui->lineEdit->text().toDouble()

      Try QLocale::toDouble() instead.

      Regards

      Qt has to stay free or it will die.

      G 1 Reply Last reply
      0
      • aha_1980A aha_1980

        @Gourmet

        ui->lineEdit->text().toDouble()

        Try QLocale::toDouble() instead.

        Regards

        G Offline
        G Offline
        Gourmet
        wrote on last edited by
        #3

        @aha_1980 said in This funny decimal point...:

        Try QLocale::toDouble() instead.

        Oh, my... This is not even a static function...

        But what if I want show digital keyboard with "." button?

        aha_1980A 1 Reply Last reply
        0
        • G Gourmet

          @aha_1980 said in This funny decimal point...:

          Try QLocale::toDouble() instead.

          Oh, my... This is not even a static function...

          But what if I want show digital keyboard with "." button?

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Gourmet said in This funny decimal point...:

          @aha_1980 said in This funny decimal point...:

          Try QLocale::toDouble() instead.

          Oh, my... This is not even a static function...

          Yeah, but it works :)

          But what if I want show digital keyboard with "." button?

          Sorry, out of scope for me

          Qt has to stay free or it will die.

          G 1 Reply Last reply
          0
          • aha_1980A aha_1980

            @Gourmet said in This funny decimal point...:

            @aha_1980 said in This funny decimal point...:

            Try QLocale::toDouble() instead.

            Oh, my... This is not even a static function...

            Yeah, but it works :)

            But what if I want show digital keyboard with "." button?

            Sorry, out of scope for me

            G Offline
            G Offline
            Gourmet
            wrote on last edited by Gourmet
            #5

            @aha_1980 said in This funny decimal point...:

            Yeah, but it works :)

            Yeah! But it CREATES TWO DECIMAL POINTS TOO!!! Other app part uses QML to draw values in ListView.

            text: modelData.Value
            

            In it the "." appears again!

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Out of curiosity, why not use a QDoubleSpinBox ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              G 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                Out of curiosity, why not use a QDoubleSpinBox ?

                G Offline
                G Offline
                Gourmet
                wrote on last edited by Gourmet
                #7

                @SGaist said in This funny decimal point...:

                Hi,
                Out of curiosity, why not use a QDoubleSpinBox ?

                Did you try use standard Qt controls on Android screen? They are useless. The standard spin box is VERY uncomfortable on small smartphone screen. Therefore I will need write my own decorated spinbox with large buttons. This is not needed and time wasting. And I am not sure if QDoubleSpinBox won't show virtual digital keyboard with "." and... ignore this button.

                For me it would be absolutely enough allow enter "." in QLineEdit with real validator. And not only for me. In my country about 80% people use "." for decimal point. Everywhere. I do not know who invented ","... This was stupid solution.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Gourmet said in This funny decimal point...:

                  Did you try use standard Qt controls on Android screen? They are useless. The standard spin box is VERY uncomfortable on small smartphone screen. Therefore I will need write my own decorated spinbox with large buttons. This is not needed and time wasting. And I am not sure if QDoubleSpinBox won't show virtual digital keyboard with "." and... ignore this button.

                  I overlooked the Android part. Did you consider using QtQuick.Controls ? They might suite your needs better and allow you to get your GUI working on Android faster.

                  @Gourmet said in This funny decimal point...:

                  For me it would be absolutely enough allow enter "." in QLineEdit with real validator. And not only for me. In my country about 80% people use "." for decimal point. Everywhere. I do not know who invented ","... This was stupid solution.

                  Locales existed way before computers were even the glimpse of an idea.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  G 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    @Gourmet said in This funny decimal point...:

                    Did you try use standard Qt controls on Android screen? They are useless. The standard spin box is VERY uncomfortable on small smartphone screen. Therefore I will need write my own decorated spinbox with large buttons. This is not needed and time wasting. And I am not sure if QDoubleSpinBox won't show virtual digital keyboard with "." and... ignore this button.

                    I overlooked the Android part. Did you consider using QtQuick.Controls ? They might suite your needs better and allow you to get your GUI working on Android faster.

                    @Gourmet said in This funny decimal point...:

                    For me it would be absolutely enough allow enter "." in QLineEdit with real validator. And not only for me. In my country about 80% people use "." for decimal point. Everywhere. I do not know who invented ","... This was stupid solution.

                    Locales existed way before computers were even the glimpse of an idea.

                    G Offline
                    G Offline
                    Gourmet
                    wrote on last edited by
                    #9

                    @SGaist said in This funny decimal point...:

                    Did you consider using QtQuick.Controls ?

                    I use QtQuick for other interface part - for scrolling history list of this line edit. But this list build logic is little complex and is not suitable for QML. Or better say - on C++ it is implemented easier. I confess following religion - QML/QtQuick only for views, but Qt/C++ for models and business logic. Therefore QLineEdit is most suitable solution. It works fine. But how force validator pass "." instead of "," in this edit only?

                    JKSHJ 1 Reply Last reply
                    0
                    • G Gourmet

                      @SGaist said in This funny decimal point...:

                      Did you consider using QtQuick.Controls ?

                      I use QtQuick for other interface part - for scrolling history list of this line edit. But this list build logic is little complex and is not suitable for QML. Or better say - on C++ it is implemented easier. I confess following religion - QML/QtQuick only for views, but Qt/C++ for models and business logic. Therefore QLineEdit is most suitable solution. It works fine. But how force validator pass "." instead of "," in this edit only?

                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #10

                      @Gourmet said in This funny decimal point...:

                      I tried use

                      realvalidator->setLocale(QLocale(QLocale::Arabic));
                      

                      but this... prohibits input both "," and "."

                      This sounds very strange.

                      Does this also happen on your development computer? Or does it only happen on your Android device?

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      G 1 Reply Last reply
                      0
                      • JKSHJ JKSH

                        @Gourmet said in This funny decimal point...:

                        I tried use

                        realvalidator->setLocale(QLocale(QLocale::Arabic));
                        

                        but this... prohibits input both "," and "."

                        This sounds very strange.

                        Does this also happen on your development computer? Or does it only happen on your Android device?

                        G Offline
                        G Offline
                        Gourmet
                        wrote on last edited by Gourmet
                        #11

                        @JKSH said in This funny decimal point...:

                        Does this also happen on your development computer? Or does it only happen on your Android device?

                        The same behavior is on Android and Linux Kubuntu development station. Probably this should be done by some other manner. But I do not see docs or examples.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          Gourmet
                          wrote on last edited by
                          #12

                          @JKSH said in This funny decimal point...:

                          realvalidator->setLocale(QLocale(QLocale::Arabic));

                          realvalidator->setLocale(QLocale(QLocale::English));
                          

                          works with ".". Do Arabic numbers not include decimal points?...

                          J.HilkJ 1 Reply Last reply
                          0
                          • G Gourmet

                            @JKSH said in This funny decimal point...:

                            realvalidator->setLocale(QLocale(QLocale::Arabic));

                            realvalidator->setLocale(QLocale(QLocale::English));
                            

                            works with ".". Do Arabic numbers not include decimal points?...

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

                            @Gourmet
                            google says, Arabic decimal point is U+066B whereas the rest of the world uses U+2396 and they have a different separator for thousands

                            https://en.wikipedia.org/wiki/Decimal_separator#Other_numeral_systems


                            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
                            5

                            • Login

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