PDA

View Full Version : Validating QLineEdit



OriginalCopy
8th November 2007, 16:46
I'm trying to validate the input of a QLineEdit (here lineEdit_new_nickname) with a regular expression, the problem is it seem to be no validator at all, even if ->validator() returns the right QRegExpValidator. I have no idea what the problem could be. The code:



IRCSettings::IRCSettings( QWidget *parent) : QWidget(parent) {
setupUi(this);
lastPreferredNickname = NULL;
//TODO: Actually we should set the "11" part after connecting and getting RAW 005 to NICKLEN-1
//QRegExp nick_regexp("[a-zA-Z][a-zA-Z0-9[]\\\\`^{}-]{0,11}");
QRegExpValidator nick_validator(QRegExp("[a-zA-Z][a-zA-Z0-9[]\\\\`^{}-]{0,11}"),this);
lineEdit_new_nickname->setValidator(&nick_validator);
dbg() << "validator:" << lineEdit_new_nickname->validator();

dbg() << "connecting toolButton_add_nickname to listWidget_nicknames remove_nickname" <<
connect(listWidget_nicknames,SIGNAL(itemDoubleClic ked(QListWidgetItem*)),this,SLOT(remove_preferred_ nickname(QListWidgetItem*)));
dbg() << "connecting listWidget_nicknames::widgetsReordered() to this->nicknamesReordered" <<
connect(listWidget_nicknames,SIGNAL(widgetsReorder ed(QDropEvent*)),this,SLOT(nicknamesReordered(QDro pEvent*)));
/**/
}

Edit: it's not working even with the regexp ".", so the mistake is not there

jpn
8th November 2007, 16:55
The validator goes out of scope. Try:

QRegExpValidator* nick_validator = new QRegExpValidator(QRegExp("[a-zA-Z][a-zA-Z0-9[]\\\\`^{}-]{0,11}"),this);
lineEdit_new_nickname->setValidator(nick_validator);

OriginalCopy
8th November 2007, 17:12
Thank you.