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. QIntValidator not Working as Im expecting
Forum Updated to NodeBB v4.3 + New Features

QIntValidator not Working as Im expecting

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 2.8k 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.
  • Pranit PatilP Offline
    Pranit PatilP Offline
    Pranit Patil
    wrote on last edited by
    #1

    QIntValidator not Working as Im expecting
    Im set the validation on LineFdit like this

    intValidator = new QIntValidator(1,999, this);
    intValidator->setTop(999);
    intValidator->setBottom(1);
    uiPoMo->lineEdit_stId1->setValidator(intValidator);

    but still LineEdit field accepting '0' and '+' ..?

    I want to accept only 1 to 999 integer value.

    Thanks in Advance.

    @Embedded Software Developer
    God has given you one face, and you make yourself another.

    J.HilkJ 1 Reply Last reply
    0
    • Pranit PatilP Pranit Patil

      QIntValidator not Working as Im expecting
      Im set the validation on LineFdit like this

      intValidator = new QIntValidator(1,999, this);
      intValidator->setTop(999);
      intValidator->setBottom(1);
      uiPoMo->lineEdit_stId1->setValidator(intValidator);

      but still LineEdit field accepting '0' and '+' ..?

      I want to accept only 1 to 999 integer value.

      Thanks in Advance.

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

      @Pranit-Patil
      set an Input mask as well, something like:

      ...
      uiPoMo->lineEdit_stId1->setInputMask("00D");
      uiPoMo->lineEdit_stId1->setValidator(intValidator);
      

      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
      • mranger90M Offline
        mranger90M Offline
        mranger90
        wrote on last edited by
        #3

        You might want to take a look at this:

        https://www.ics.com/blog/qt-support-input-masks-and-validators

        The article is QML based, but the principles are the same and its a pretty good explanation.

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

          Or just use uiPoMo->lineEdit_stId1->setValidator(new QRegularExpressionValidator(QRegularExpression("\\d{1,3}"),this));

          "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

          aha_1980A VRoninV 2 Replies Last reply
          1
          • VRoninV VRonin

            Or just use uiPoMo->lineEdit_stId1->setValidator(new QRegularExpressionValidator(QRegularExpression("\\d{1,3}"),this));

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

            @VRonin But your validator would still allow 0 to be inserted, right?

            Qt has to stay free or it will die.

            1 Reply Last reply
            3
            • VRoninV VRonin

              Or just use uiPoMo->lineEdit_stId1->setValidator(new QRegularExpressionValidator(QRegularExpression("\\d{1,3}"),this));

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              uiPoMo->lineEdit_stId1->setValidator(new QRegularExpressionValidator(QRegularExpression("[1-9]\\d{0,2}"),this));

              "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
              5
              • Pranit PatilP Offline
                Pranit PatilP Offline
                Pranit Patil
                wrote on last edited by
                #7

                @VRonin said in QIntValidator not Working as Im expecting:

                uiPoMo->lineEdit_stId1->setValidator(new QRegularExpressionValidator(QRegularExpression("[1-9]\d{0,2}"),this));

                Its works for me

                Thank you so much to all.

                @Embedded Software Developer
                God has given you one face, and you make yourself another.

                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