PDA

View Full Version : QLineEdit problem with setValidator



dominate
20th January 2011, 11:01
Hi,

I have this problem: When I run the program I can not write any text in QLineEdit, if I set a RegExp validator for that, although I can write if I do not set a validator. What do I do wrong?

Details:

I have coded exactly the same sample in the book "C++ GUI Programming with Qt4 1st ed" (Blanchette, Summerfield) in the chapter 2, "GoToCell" example.
In that example, a new class "GoToCellDialog" is created from Ui::GoToCellDialog which inherits QDialog.
The code in gotocelldialog.cpp is this:


#include <QtGui>
#include "gotocelldialog.h"
GoToCellDialog::GoToCellDialog(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
// PROBLEM HERE: lineEdit->setValidator(new QRegExpValidator(regExp, this));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}

When I set regExp validator, I can not write any text in QLineEdit object.
However, if I do not set the validator, I can write text.
This problem occurs, although I have followed the example in the book.
Why can not I use the validator?
Any help? Any comment?

Thank you all.
Note: I am using Ubuntu 10.x and Qt4 sdk.

wysota
20th January 2011, 11:35
Did you set an input mask for the line edit in Designer?

dominate
20th January 2011, 11:45
Actually, I don't know if it is; the book was not telling any thing about that, so it is remained in its default.
Now I have looked from the Property Editor. It is like this:

Property Value
--------- ------
inputMask
translatable Checked
disambiguation
comment

So, it seems that it is not set. Do I have to do some thing?
Thank you.

wysota
20th January 2011, 13:19
No, it should be empty. So you say you can't input anything? Not even a single letter?

dominate
20th January 2011, 14:34
I have added the expressions ([A-Za-z], etc.) step by step and each time I have compiled and run again, and finally it was working with all expressions.
So rare!
Thank you much.