Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    4
    7
    3714
    Loading More Posts
    • 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
      sharon_obl82 last edited by

      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 Reply Quote 0
      • A
        andreyc last edited by

        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 Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 0
          • S
            sharon_obl82 last edited by

            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 Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              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 Reply Quote 0
              • S
                sharon_obl82 last edited by

                yes thats right

                1 Reply Last reply Reply Quote 0
                • T
                  thiberi0 last edited by

                  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 Reply Quote 0
                  • First post
                    Last post