PDA

View Full Version : setValidator on QLineEdit



osiris81
8th June 2009, 13:08
There is a method to set a validator to a QLineEdit:

void QLineEdit::setValidator(const QValidator *v)

Since the documentation does not contain many infos, I have some questions:

Is it safe to use the same Validator for more than one QLineEdit?

QDoubleValidator* doubleValidator = new QDoubleValidator(this);
ui.edit1->setValidator(doubleValidator );
ui.edit2->setValidator(doubleValidator );
ui.edit3->setValidator(doubleValidator );
ui.edit4->setValidator(doubleValidator );

I've read the sourcefile (qt 4.4.0) and saw that the QLineEdit class removes the const of the QValidator* v so it looks that the QLineEdit changes the validator...

Does an old validator gets deleted if I set a new one?

ui.edit1->setValidator( new QDoubleValidator(this) );
ui.edit1->setValidator( new QDoubleValidator(this) );

Thanks :)

wysota
8th June 2009, 14:39
Is it safe to use the same Validator for more than one QLineEdit?
Yes, it should be safe.


Does an old validator gets deleted if I set a new one?

Only if the widget you set it on is its parent.

osiris81
8th June 2009, 15:21
ok, thank you!