How to prevent space bar event from the QLineEdit
-
@maniron said in How to prevent space bar event from the QLineEdit:
[0-9]\d{1,255}
This is wrong: {1,255} means between one and 255 occurrences of the character before.
This is your reg exp:([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])
Take a look at
http://gamon.webfactional.com/regexnumericrangegenerator/
https://regex101.comQRegExp 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
-
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
@maniron You know that you have to escape special characters in C++ string literals?
If you have C++11 compiler you can simply doR"(([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]))"
-
@maniron You know that you have to escape special characters in C++ string literals?
If you have C++11 compiler you can simply doR"(([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]))"
-
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. -
@maniron The compiler is configured in the Kit.
But actually you could simply copy what I posted and see whether it works...@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);
-
@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);
@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?
-
@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?
-
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);
}
-
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);
}
@maniron said in How to prevent space bar event from the QLineEdit:
ui->lineEdit->setInputMask("000.000.000.000");
Why is this line there?
-
@maniron said in How to prevent space bar event from the QLineEdit:
ui->lineEdit->setInputMask("000.000.000.000");
Why is this line there?
-
@maniron said in How to prevent space bar event from the QLineEdit:
to form the IP format
For that you now have the validator!
-
@maniron said in How to prevent space bar event from the QLineEdit:
to form the IP format
For that you now have the validator!
@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 -
@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