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] How to allow ONLY numbers being entered in qlineedit in Chinese mode?
QtWS25 Last Chance

[SOLVED] How to allow ONLY numbers being entered in qlineedit in Chinese mode?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 4.3k 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.
  • S Offline
    S Offline
    sharon_obl82
    wrote on last edited by
    #1

    Hi,
    I have a qlineedit that only accepts numbers. I added QValidator such as the code below:

    @
    QLineEdit *edit = ui->lineEdit_2;
    QValidator *validator = new QIntValidator(1,13999999);
    edit->setValidator(validator);
    @

    But if i change the language to Chinese, i am able to enter Chinese characters into the qlineedit too! Does anyone know how to prevent such thing from happening?

    Thank you!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      What does this code return in your environment?
      @
      QString str;
      int pos = 0;
      QIntValidator v(1, 13999999, this);

      str = "String in Chinese";
      qDebug() << v.validate(str, pos);
      @

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

        Hi,

        Why not just use a QSpinBox ?

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sharon_obl82
          wrote on last edited by
          #4

          thanks SGaist, I think i will just use QSpinbox instead.
          Btw when I put QSpinbox, there's always a number there, like 0 or 1. How do I make it disappear?

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

            Do you mean you want an empty QSpinBox ?

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sharon_obl82
              wrote on last edited by
              #6

              yes thats right

              1 Reply Last reply
              0
              • T Offline
                T Offline
                thiberi0
                wrote on last edited by
                #7

                I have found this thread:
                http://qt-project.org/faq/answer/how_can_i_set_an_empty_default_value_in_qspinbox

                thiberi0

                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