Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
When we hit a button , it will call slot accordingly. Now I want to know the objectname of that button in the slot.
These are dynamics buttons with custom names.
you can use QObject::sender() to get the sending object. There you can query for the object name:
@ void myslot() { QObject* pObject = sender(); QString name = pObject->objectName(); } @
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.