Unsolved How to prevent space bar event from the QLineEdit
-
@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?
-
@jsulm yes
-
@maniron Works for me. Where did you put that code?
-
@jsulm in my constructor
-
@maniron Please show your constructor
-
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?
-
@jsulm to form the IP format
-
@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 -
@maniron You can do this when the user presses the button. To do so you can even use same regular expression.