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. How to prevent space bar event from the QLineEdit
Forum Updated to NodeBB v4.3 + New Features

How to prevent space bar event from the QLineEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
29 Posts 4 Posters 5.6k 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.
  • ManiRonM ManiRon

    @jsulm

      QRegExp rx("([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])");
    

    Is this right ? cause same problem arises the line edit is not accepting any numbers

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #11

    @maniron You know that you have to escape special characters in C++ string literals?
    If you have C++11 compiler you can simply do

    R"(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))"
    

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    ManiRonM 1 Reply Last reply
    1
    • jsulmJ jsulm

      @maniron You know that you have to escape special characters in C++ string literals?
      If you have C++11 compiler you can simply do

      R"(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))"
      
      ManiRonM Offline
      ManiRonM Offline
      ManiRon
      wrote on last edited by
      #12

      @jsulm I am using QT 5.5.0

      JonBJ 1 Reply Last reply
      0
      • ManiRonM ManiRon

        @jsulm I am using QT 5.5.0

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

        @maniron
        You have to tell @jsulm which compiler version you are using, not which Qt version.

        ManiRonM 1 Reply Last reply
        3
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #14

          Hi
          try to add
          CONFIG += c++11
          to your .pro file and run qmake
          it should work.
          Then you can use the handy R" syntax and avoid
          having to escape the exp string.

          1 Reply Last reply
          0
          • JonBJ JonB

            @maniron
            You have to tell @jsulm which compiler version you are using, not which Qt version.

            ManiRonM Offline
            ManiRonM Offline
            ManiRon
            wrote on last edited by
            #15

            @jonb it doesnt show any co mpiler version

            JonBJ jsulmJ 2 Replies Last reply
            0
            • ManiRonM ManiRon

              @jonb it doesnt show any co mpiler version

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #16

              @maniron
              What doesn't show any compiler version? If you are developing with Qt you should know which compiler you chose and what version it is at, that was your choice, not Qt's.

              1 Reply Last reply
              0
              • ManiRonM ManiRon

                @jonb it doesnt show any co mpiler version

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #17

                @maniron The compiler is configured in the Kit.
                But actually you could simply copy what I posted and see whether it works...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                ManiRonM 1 Reply Last reply
                2
                • jsulmJ jsulm

                  @maniron The compiler is configured in the Kit.
                  But actually you could simply copy what I posted and see whether it works...

                  ManiRonM Offline
                  ManiRonM Offline
                  ManiRon
                  wrote on last edited by
                  #18

                  @jsulm
                  I tried adding this but still the line edit is not getting any input
                  ui->lineEdit->setInputMask("000.000.000.000");

                    QRegExp rx(R"(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))");
                  // the validator treats the regexp as "^[1-9]\\d{0,3}$"
                  QRegExpValidator *ipValidator = new QRegExpValidator(rx, this);
                  ui->lineEdit->setValidator(ipValidator);
                  
                  jsulmJ 1 Reply Last reply
                  0
                  • ManiRonM ManiRon

                    @jsulm
                    I tried adding this but still the line edit is not getting any input
                    ui->lineEdit->setInputMask("000.000.000.000");

                      QRegExp rx(R"(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))");
                    // the validator treats the regexp as "^[1-9]\\d{0,3}$"
                    QRegExpValidator *ipValidator = new QRegExpValidator(rx, this);
                    ui->lineEdit->setValidator(ipValidator);
                    
                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #19

                    @maniron said in How to prevent space bar event from the QLineEdit:

                    line edit is not getting any input

                    Do you mean you can't input anything?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    ManiRonM 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @maniron said in How to prevent space bar event from the QLineEdit:

                      line edit is not getting any input

                      Do you mean you can't input anything?

                      ManiRonM Offline
                      ManiRonM Offline
                      ManiRon
                      wrote on last edited by
                      #20

                      @jsulm yes

                      jsulmJ 1 Reply Last reply
                      0
                      • ManiRonM ManiRon

                        @jsulm yes

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #21

                        @maniron Works for me. Where did you put that code?

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        ManiRonM 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @maniron Works for me. Where did you put that code?

                          ManiRonM Offline
                          ManiRonM Offline
                          ManiRon
                          wrote on last edited by
                          #22

                          @jsulm in my constructor

                          jsulmJ 1 Reply Last reply
                          0
                          • ManiRonM ManiRon

                            @jsulm in my constructor

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #23

                            @maniron Please show your constructor

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            ManiRonM 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @maniron Please show your constructor

                              ManiRonM Offline
                              ManiRonM Offline
                              ManiRon
                              wrote on last edited by
                              #24

                              @jsulm

                              MainWindow::MainWindow(QWidget *parent) :
                              QMainWindow(parent),
                              ui(new Ui::MainWindow)
                              {
                              ui->setupUi(this);
                              ui->lineEdit->setInputMask("000.000.000.000");
                              QRegExp rx(R"(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).([0-9]|[1-8][0-
                              9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-
                              9]|25[0-5]).([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))");
                              // the validator treats the regexp as "^[1-9]\d{0,3}$"
                              QRegExpValidator *ipValidator = new QRegExpValidator(rx, this);

                              ui->lineEdit->setValidator(ipValidator);
                              

                              }

                              jsulmJ 1 Reply Last reply
                              0
                              • ManiRonM ManiRon

                                @jsulm

                                MainWindow::MainWindow(QWidget *parent) :
                                QMainWindow(parent),
                                ui(new Ui::MainWindow)
                                {
                                ui->setupUi(this);
                                ui->lineEdit->setInputMask("000.000.000.000");
                                QRegExp rx(R"(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).([0-9]|[1-8][0-
                                9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-
                                9]|25[0-5]).([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))");
                                // the validator treats the regexp as "^[1-9]\d{0,3}$"
                                QRegExpValidator *ipValidator = new QRegExpValidator(rx, this);

                                ui->lineEdit->setValidator(ipValidator);
                                

                                }

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #25

                                @maniron said in How to prevent space bar event from the QLineEdit:

                                ui->lineEdit->setInputMask("000.000.000.000");

                                Why is this line there?

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                ManiRonM 1 Reply Last reply
                                0
                                • jsulmJ jsulm

                                  @maniron said in How to prevent space bar event from the QLineEdit:

                                  ui->lineEdit->setInputMask("000.000.000.000");

                                  Why is this line there?

                                  ManiRonM Offline
                                  ManiRonM Offline
                                  ManiRon
                                  wrote on last edited by
                                  #26

                                  @jsulm to form the IP format

                                  jsulmJ 1 Reply Last reply
                                  0
                                  • ManiRonM ManiRon

                                    @jsulm to form the IP format

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #27

                                    @maniron said in How to prevent space bar event from the QLineEdit:

                                    to form the IP format

                                    For that you now have the validator!

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    ManiRonM 1 Reply Last reply
                                    1
                                    • jsulmJ jsulm

                                      @maniron said in How to prevent space bar event from the QLineEdit:

                                      to form the IP format

                                      For that you now have the validator!

                                      ManiRonM Offline
                                      ManiRonM Offline
                                      ManiRon
                                      wrote on last edited by
                                      #28

                                      @jsulm Yes it worked but if the user is giving an input which is not in the form of an Ip
                                      (For Example : I am entering an input as 255 and pressing a button also it accepts the input )
                                      Is there a way which checks whether the entered Ip address is in the form of an IP Address

                                      jsulmJ 1 Reply Last reply
                                      0
                                      • ManiRonM ManiRon

                                        @jsulm Yes it worked but if the user is giving an input which is not in the form of an Ip
                                        (For Example : I am entering an input as 255 and pressing a button also it accepts the input )
                                        Is there a way which checks whether the entered Ip address is in the form of an IP Address

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #29

                                        @maniron You can do this when the user presses the button. To do so you can even use same regular expression.

                                        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