PDA

View Full Version : QLineEdit inputMask and validator



vhptt
3rd August 2012, 08:30
I have a Widget with a LineEdit in it. Input of LineEdit must be restrict special symbol. I used inputMask to do this work.
But, now I have trouble.

ui->lineEdit->setInputMask("N");
The code above allow me to input only 1 character.

ui->lineEdit->setInputMask("NNN");
The code above allow me to input only 3 character.

Assumming, the lineEdit allow user input maxlength = 1000, so I have do this:

ui->lineEdit->setInputMask("NNNNNNNNNNNNNNNNNN.......N (1000 times)");
Very stupid. Is there another way to avoid that. How can I solve ????)

sonulohani
3rd August 2012, 10:10
yes,,,, put all that in for loop like this:-



QString str;
for(int i=0;i<1000;i++){
str.append("N");
}
ui->lineEdit->setInputMask(str);


Got it or still confused.

hvengel
31st August 2012, 23:00
Even simpler:

QString mask(1000, QChar(' '));

ChrisW67
1st September 2012, 02:36
1000 characters with no spaces, line breaks, or punctuation? Really?