Hi everyone,
I'm new to Qt and while reading the book "C++ GUI Programming with Qt 4" I found the following piece of code:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
|
GoToCellDialog::GoToCellDialog(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp, this));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}
|
So, regExp is an object of the type QRegExp created locally (on stack), which is latter passed to QRegExpValidator constructor as refence! Why doesn't it cause an error? Function ends and stack is cleaned long before Validator is executed for the first time, so the reference can point to some random data! What is going on?
Cheers,
Kisielewski