View Full Version : Is there a way to know when an object's objectName() changes?

12th August 2009, 16:14

Is there a way to know when setObjectName() is called on an object? I couldn't find a signal or event related to this. Thus, is there a clever way to know this?


12th August 2009, 16:40
As far as I remember there is an internal event that gets posted to the widget but it's not in the API. But I'm not sure if I'm right - you'd have to check in the sources of QObject.

13th August 2009, 21:24
Why don't you subclass and implement the method yourself? Then you can emit a signal when it's called.

14th August 2009, 00:06
Why don't you subclass and implement the method yourself

Because QObject::setObjectName() is not virtual.

14th August 2009, 08:44
Thanks for the responses. Apart from the fact that setObjectName() is not virtual, I want to be able to monitor any QObject based class, thus a subclass wouldn't have done the job even if it was virtual.

I have not had time to look at the sources yet, but will do so.

Thanks for the help.

14th August 2009, 14:23
Hiya, I just looked at the sources for 4.5.2 and I'm afraid I can't find any emitted signal. The code for QObject::setObjectName is simply...

void QObject::setObjectName(const QString &name)
d->objectName = name;

No internal event, no signal. Ho hum. I'm afraid I've got no solutions for you beyond adding this feature to Qt yourself. This is quite do-able but you'll be stuck with a version of Qt source differing from the release versions which could prove to be a maintenance problem for you. If this is just for debugging then you'll probably get away with it.

17th August 2009, 09:55

Thanks for checking it, I didn't get to it yet.

I'll have to make another plan then, I really need this. I'll perhaps use my own dynamic property then since there is a signal which is emitted when dynamic properties change.

Thanks again,