What would be object name which sends event (Solved)
-
Use QObject::sender() inside your slot to get a pointer to the emitter object.
-
Be aware, that the object returned by sender() is only valid if the slot is called via signal/slot connection (using QObject::connect() method). When the slot is called directly, sender() returns a null pointer.
-
Thank you Gerolf Reinwardt
Yes Volker it's via signal/slot
-
Good. Nontheless, I'd put a check if(pObject) { ... } around the code, just to be on the save side.
-
Ok nice. Now I'll also :)
-
I wanted to keep it as small as possible, but I would also do it :-)
-
To save you a line :-) you can write this:
@
void myslot()
{
if(QObject* pObject = sender()) {
QString name = pObject->objectName();
}
}
@ -
QSignalMapper might be an option for you, too.
-
It's rocking guys
Nice one Volker :)[quote author="Gerolf Reinwardt" date="1292514405"]I wanted to keep it as small as possible, but I would also do it :-)[/quote]
Totally agreed with you :)
-
[quote author="Tobias Hunger" date="1292515404"]QSignalMapper might be an option for you, too.[/quote]
Let me check this out.