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. line edit
Forum Updated to NodeBB v4.3 + New Features

line edit

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 6 Posters 996 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.
  • M Offline
    M Offline
    muhammed hayr
    wrote on last edited by
    #1

    Hello
    I had a question, I hope you can help,
    I have set it to take 15 characters in line edit, I want the period to be entered only once, otherwise it will give a warning when "more than one point is entered", can you help with this?
    thanks .

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Emre MUTLU
      wrote on last edited by Emre MUTLU
      #2
      int i=ui->lineEdit->Text().length();
      if(i>=15)
      {
      qDebug()<<"more than one point is entered.";
      }
      

      like this?

      M 2 Replies Last reply
      0
      • E Emre MUTLU
        int i=ui->lineEdit->Text().length();
        if(i>=15)
        {
        qDebug()<<"more than one point is entered.";
        }
        

        like this?

        M Offline
        M Offline
        muhammed hayr
        wrote on last edited by
        #3

        @Emre-MUTLU

        thank you for replying
        I mean, "When I enter the number 15.96, the transactions continue"
        "I want it to give an error when 15.9.6. is entered in this way"
        thank you for helping

        1 Reply Last reply
        0
        • Cobra91151C Offline
          Cobra91151C Offline
          Cobra91151
          wrote on last edited by
          #4

          Hello!

          If you want to check the numbers in your QLineEdit, I would suggest to set the validator for example - QDoubleValidator: https://doc.qt.io/qt-5/qdoublevalidator.html
          For int value, there is QIntValidator: https://doc.qt.io/qt-5/qintvalidator.html#details

          1 Reply Last reply
          1
          • E Emre MUTLU
            int i=ui->lineEdit->Text().length();
            if(i>=15)
            {
            qDebug()<<"more than one point is entered.";
            }
            

            like this?

            M Offline
            M Offline
            muhammed hayr
            wrote on last edited by
            #5

            @Emre-MUTLU
            can you please explain more

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Emre MUTLU
              wrote on last edited by
              #6

              Do you want to separate by dots ? or value ? i don't get this

              M 1 Reply Last reply
              0
              • E Emre MUTLU

                Do you want to separate by dots ? or value ? i don't get this

                M Offline
                M Offline
                muhammed hayr
                wrote on last edited by
                #7

                @Emre-MUTLU
                I want only one point to be entered
                I want it to give an error even though more than one point is entered

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  Emre MUTLU
                  wrote on last edited by
                  #8

                  There are better ways but this came to mind.

                  QString str=ui->lineEdit->Text();
                  QStringList list;
                  for(int i=0;i<ui->lineEdit->Text().Length();i++)
                  {
                  list=str.split(".");
                  }
                  if(list.Length()>2)
                  {
                  qDebug()<<" more than one point is entered";
                  }
                  
                  qwasder85Q E 2 Replies Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi,

                    Why not use a QDoubleSpinBox for your number input ?

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

                    M 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      Hi,

                      Why not use a QDoubleSpinBox for your number input ?

                      M Offline
                      M Offline
                      muhammed hayr
                      wrote on last edited by
                      #10

                      @SGaist
                      can you give an example

                      jsulmJ 1 Reply Last reply
                      0
                      • M muhammed hayr

                        @SGaist
                        can you give an example

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

                        @muhammed-hayr If you open the link @SGaist gave you you will find a link "Spin Boxes Example"...

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

                        M 1 Reply Last reply
                        1
                        • jsulmJ jsulm

                          @muhammed-hayr If you open the link @SGaist gave you you will find a link "Spin Boxes Example"...

                          M Offline
                          M Offline
                          muhammed hayr
                          wrote on last edited by
                          #12

                          @jsulm
                          I am using numpad

                          jsulmJ 1 Reply Last reply
                          0
                          • M muhammed hayr

                            @jsulm
                            I am using numpad

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

                            @muhammed-hayr said in line edit:

                            I am using numpad

                            ?

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

                            1 Reply Last reply
                            1
                            • E Emre MUTLU

                              There are better ways but this came to mind.

                              QString str=ui->lineEdit->Text();
                              QStringList list;
                              for(int i=0;i<ui->lineEdit->Text().Length();i++)
                              {
                              list=str.split(".");
                              }
                              if(list.Length()>2)
                              {
                              qDebug()<<" more than one point is entered";
                              }
                              
                              qwasder85Q Offline
                              qwasder85Q Offline
                              qwasder85
                              wrote on last edited by qwasder85
                              #14

                              @Emre-MUTLU Why the loop?

                              Shorter version:

                              QString text = myLineEdit.text();
                              
                              if (2 < text.split('.', Qt::KeepEmptyParts).length())
                                  // Display your warning
                              

                              The cleaner way would be a RegEx validator in my opinion. Although this here should work and would be way less effort, haha.

                              1 Reply Last reply
                              0
                              • E Emre MUTLU

                                There are better ways but this came to mind.

                                QString str=ui->lineEdit->Text();
                                QStringList list;
                                for(int i=0;i<ui->lineEdit->Text().Length();i++)
                                {
                                list=str.split(".");
                                }
                                if(list.Length()>2)
                                {
                                qDebug()<<" more than one point is entered";
                                }
                                
                                E Offline
                                E Offline
                                Emre MUTLU
                                wrote on last edited by
                                #15

                                @Emre-MUTLU said in line edit:

                                There are better ways but this came to mind.
                                ?

                                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