PDA

View Full Version : on_LineEditX_textChanged()



gt.beta2
5th February 2009, 21:35
Hi!
I have some lineEdits in a form among other:
lineEdit1, lineEdit2, lineEdit3 ...

I implemented a member function to be executed when any of them are edited:
on_lineEdit1_textChanged(), on_lineEdit2_textChanged(), on_lineEdit3_textChanged() ...

They all have the same code, because the textChanged event validates the content of all lineEdits in that set and performs some calculations with their content if all are valid.

The question is if there is a way to control the "textChanged" in a set of lineEdits without having to do what i "tried:rolleyes:" to describe above?

Thanks in advance.

janus
5th February 2009, 22:18
Hi,

there is something like a signalmapper. But I haven't used it.

gt.beta2
5th February 2009, 22:20
Thanks
I will take a look at it!

Persoontje
15th February 2009, 12:11
You can connect the signal emitted by the lineedits manually to one singe slot.

In your class definition:


private slot:
void checkLineEdit();


Then you connect all your signals to the slot in the constructor



connect(ui.lineEdit1, SIGNAL(textChanged()), this, SLOT(checkLineEdit());


In the slot you can then get the object which emmited the signal using the sender function():



QLineEdit* lineEdit = qobject_cast<QLineEdit*>(sender());