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. How to restrict QSpinBox value to 1 to 100?
Forum Updated to NodeBB v4.3 + New Features

How to restrict QSpinBox value to 1 to 100?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
20 Posts 5 Posters 3.3k 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.
  • JonBJ JonB

    @KillerSmath
    How would your regexp allow a value like, say, 23? How would it prevent, say, 999?

    KillerSmathK Offline
    KillerSmathK Offline
    KillerSmath
    wrote on last edited by
    #10

    @JonB said in How to restrict QSpinBox value to 1 to 100?:

    @KillerSmath
    How would your regexp allow a value like, say, 23? How would it prevent, say, 999?

    I just said a hypothetical example.

    @Computer Science Student - Brazil
    Web Developer and Researcher
    “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

    JonBJ 1 Reply Last reply
    1
    • KillerSmathK KillerSmath

      @JonB said in How to restrict QSpinBox value to 1 to 100?:

      @KillerSmath
      How would your regexp allow a value like, say, 23? How would it prevent, say, 999?

      I just said a hypothetical example.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #11

      @KillerSmath
      Oh, OK, some posters here will type in whatever you offer and then complain if it doesn't work as-is!

      KillerSmathK 1 Reply Last reply
      1
      • JonBJ JonB

        @KillerSmath
        Oh, OK, some posters here will type in whatever you offer and then complain if it doesn't work as-is!

        KillerSmathK Offline
        KillerSmathK Offline
        KillerSmath
        wrote on last edited by
        #12

        @JonB said in How to restrict QSpinBox value to 1 to 100?:

        @KillerSmath
        Oh, OK, some posters here will type in whatever you offer and then complain if it doesn't work as-is!

        an easy mode to write this regular expression is 0|100|[1-9][0-9]?

        @Computer Science Student - Brazil
        Web Developer and Researcher
        “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

        JonBJ 1 Reply Last reply
        2
        • KillerSmathK KillerSmath

          @JonB said in How to restrict QSpinBox value to 1 to 100?:

          @KillerSmath
          Oh, OK, some posters here will type in whatever you offer and then complain if it doesn't work as-is!

          an easy mode to write this regular expression is 0|100|[1-9][0-9]?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #13

          @KillerSmath
          Yep. For completeness, since the OP states he wants to disallow 0, if he wants to copy this it should be 100|[1-9][0-9]?.

          KillerSmathK 1 Reply Last reply
          0
          • JonBJ JonB

            @KillerSmath
            Yep. For completeness, since the OP states he wants to disallow 0, if he wants to copy this it should be 100|[1-9][0-9]?.

            KillerSmathK Offline
            KillerSmathK Offline
            KillerSmath
            wrote on last edited by
            #14

            @JonB said in How to restrict QSpinBox value to 1 to 100?:

            @KillerSmath
            Yep. For completeness, since the OP states he wants to disallow 0, if he wants to copy this it should be 100|[1-9][0-9]?.

            Yep, thank you, i forgot this part. xD

            @Computer Science Student - Brazil
            Web Developer and Researcher
            “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

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

              To be correct: ^[1-9][0-9]?$|^100$. Otherwise you'll be matching "numbers in numbers"

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

              KillerSmathK JonBJ 2 Replies Last reply
              2
              • SGaistS SGaist

                To be correct: ^[1-9][0-9]?$|^100$. Otherwise you'll be matching "numbers in numbers"

                KillerSmathK Offline
                KillerSmathK Offline
                KillerSmath
                wrote on last edited by KillerSmath
                #16

                @SGaist said in How to restrict QSpinBox value to 1 to 100?:

                To be correct: ^[1-9][0-9]?$|^100$. Otherwise you'll be matching "numbers in numbers"

                Yes, use the delimiters to apply this regular expression on full string.

                @Computer Science Student - Brazil
                Web Developer and Researcher
                “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                1 Reply Last reply
                0
                • SGaistS SGaist

                  To be correct: ^[1-9][0-9]?$|^100$. Otherwise you'll be matching "numbers in numbers"

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #17

                  @SGaist

                  To be correct: ^[1-9][0-9]?$|^100$. Otherwise you'll be matching "numbers in numbers"

                  But for QAbstractSpinBox::validate() I assume it uses http://doc.qt.io/qt-5/qregularexpressionvalidator.html#details, which states:

                  QRegularExpressionValidator automatically wraps the regular expression in the \A and \z anchors; in other words, it always attempts to do an exact match.

                  ?

                  KillerSmathK 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @SGaist

                    To be correct: ^[1-9][0-9]?$|^100$. Otherwise you'll be matching "numbers in numbers"

                    But for QAbstractSpinBox::validate() I assume it uses http://doc.qt.io/qt-5/qregularexpressionvalidator.html#details, which states:

                    QRegularExpressionValidator automatically wraps the regular expression in the \A and \z anchors; in other words, it always attempts to do an exact match.

                    ?

                    KillerSmathK Offline
                    KillerSmathK Offline
                    KillerSmath
                    wrote on last edited by KillerSmath
                    #18

                    @JonB said in How to restrict QSpinBox value to 1 to 100?:

                    @SGaist

                    To be correct: ^[1-9][0-9]?$|^100$. Otherwise you'll be matching "numbers in numbers"

                    But for QAbstractSpinBox::validate() I assume it uses http://doc.qt.io/qt-5/qregularexpressionvalidator.html#details, which states:

                    QRegularExpressionValidator automatically wraps the regular expression in the \A and \z anchors; in other words, it always attempts to do an exact match.

                    ?

                    Yes, i found the Qt reposity and i noticed QAbstractSpinBox::validate() returns for default QValidator::Acceptable without verification.

                    if the input is not validated to QValidator::Acceptable when Return is pressed or interpretText() is called.

                    QAbstractSpinBox.cpp Repository

                    @Computer Science Student - Brazil
                    Web Developer and Researcher
                    “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                    JonBJ 1 Reply Last reply
                    0
                    • KillerSmathK KillerSmath

                      @JonB said in How to restrict QSpinBox value to 1 to 100?:

                      @SGaist

                      To be correct: ^[1-9][0-9]?$|^100$. Otherwise you'll be matching "numbers in numbers"

                      But for QAbstractSpinBox::validate() I assume it uses http://doc.qt.io/qt-5/qregularexpressionvalidator.html#details, which states:

                      QRegularExpressionValidator automatically wraps the regular expression in the \A and \z anchors; in other words, it always attempts to do an exact match.

                      ?

                      Yes, i found the Qt reposity and i noticed QAbstractSpinBox::validate() returns for default QValidator::Acceptable without verification.

                      if the input is not validated to QValidator::Acceptable when Return is pressed or interpretText() is called.

                      QAbstractSpinBox.cpp Repository

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #19

                      @KillerSmath
                      Not sure your comment is against what I meant?
                      I was asking @SGaist why it is necessary to put in his ^ & $ in the reg exp given that the docs for http://doc.qt.io/qt-5/qregularexpressionvalidator.html#details (seem to me to) state that it will do full match anyway? Unless QAbstractSpinBox::validate() does not use QRegularExpressionValidator ?

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

                        @JonB That was for direct QRegularExpression use.

                        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
                        1

                        • Login

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