line edit
-
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 . -
int i=ui->lineEdit->Text().length(); if(i>=15) { qDebug()<<"more than one point is entered."; }like this?
-
int i=ui->lineEdit->Text().length(); if(i>=15) { qDebug()<<"more than one point is entered."; }like this?
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 -
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
Forintvalue, there isQIntValidator: https://doc.qt.io/qt-5/qintvalidator.html#details -
int i=ui->lineEdit->Text().length(); if(i>=15) { qDebug()<<"more than one point is entered."; }like this?
@Emre-MUTLU
can you please explain more -
Do you want to separate by dots ? or value ? i don't get this
-
Do you want to separate by dots ? or value ? i don't get this
@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 -
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"; } -
Hi,
Why not use a QDoubleSpinBox for your number input ?
-
Hi,
Why not use a QDoubleSpinBox for your number input ?
@SGaist
can you give an example -
@SGaist
can you give an example@muhammed-hayr If you open the link @SGaist gave you you will find a link "Spin Boxes Example"...
-
@muhammed-hayr If you open the link @SGaist gave you you will find a link "Spin Boxes Example"...
@jsulm
I am using numpad -
@jsulm
I am using numpad -
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"; }@Emre-MUTLU Why the loop?
Shorter version:
QString text = myLineEdit.text(); if (2 < text.split('.', Qt::KeepEmptyParts).length()) // Display your warningThe cleaner way would be a RegEx validator in my opinion. Although this here should work and would be way less effort, haha.
-
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"; }@Emre-MUTLU said in line edit:
There are better ways but this came to mind.
?