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] QLineEdit Should accept only integers and " and / characters??
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QLineEdit Should accept only integers and " and / characters??

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 8.4k Views 1 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.
  • M Offline
    M Offline
    Macro
    wrote on last edited by
    #1

    Hi.....

    I have a QLineEdit & Am using it for a Measurement Conversion Application... In that QLineEdit i have to use only the Integers values. so i used the QDoubleValidator.

    @q_LineEdit->setValidator(new QDoubleValidator(this));@

    Now i want the QLineEdit to accept only " and / characters to it, as it is required for the conversion application. how can i make my QLineEdit to accept it while using a QDoubleValidator... Pls give ur suggestions....

    Thanks & Regards

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You need to use "QRegExpValidator":http://qt-project.org/doc/qt-4.8/qregexpvalidator.html.

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Macro
        wrote on last edited by
        #3

        Thanks for your suggestion sierdzio.

        If i use a QRegExpValidator, it will acept all the characters. (including alphabets too). I don't want my QLineEdit to accept the alphabets or any other characters except this " and / in it.

        Thanks and Regards.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @
          QRegExpValidator("("|/)");
          // or
          QRegExpValidator("("|/){1}");
          @

          (Z(:^

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Macro
            wrote on last edited by
            #5

            Already i had tried in this way
            @QRegExpValidator("("|/)"); @

            and i failed because i can only enter either one of the characters in my line edit, also i want to enter other integer values (0-9 as double values).

            Note: I want my Line Edit to behave something like this (eg. 70"1/2).

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              OK, you did not specify that in your initial post. Just follow the tutorial on "QRegExp":http://qt-project.org/doc/qt-4.8/qregexp.html, it's quite well written.

              Don't expect regExps to be easy, though ;) Also, in Qt5, you can use QRegularExpression.

              (Z(:^

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Macro
                wrote on last edited by
                #7

                Yup... I know that QRegExp is not quite easy. anyways thanks for your suggestions.. :-)

                Thanks & Regards

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

                  Just use:
                  @
                  QRegExpValidator("["/\d]");
                  @

                  "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
                  0
                  • M Offline
                    M Offline
                    Macro
                    wrote on last edited by
                    #9

                    Yup... I got it.... Thanks for your suggestion.... :-)

                    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