PDA

View Full Version : Getting type of object



steg90
29th November 2007, 14:51
Hi,

Is there anyway to determine the type of an object? I have various QWidgets ( QPushButton, QCheckBox ) that are connected to a QSignalMapper and go to the same slot. In this slot, I'd like to know if it was a QCheckBox that caused the signal to be raised or QPushButton, is this possible?

Regards,
Steve

jacek
29th November 2007, 14:58
For all QObjects you can use QMetaObject::className(), but if you have to distinguish between check boxes and push buttons, then most likely you need two slots.

Khal Drogo
29th November 2007, 14:58
Hello.

I haven't used QSignalMapper, and quite possibly that provides a better option somewhere.

I'd check QMetaObject, especially with regards to the className() method.

Good luck.

wysota
29th November 2007, 15:38
Using qobject_cast<>() is probably the most straightforward thing to do.