findChild(ObjectName) fails?
I have a main window which creates multi QWidgets during running. I want to pick up one of them by their Object Name. But when I use findChild(Object Name), it always returns 0. For example,
at the creation of a widget, I used
Code:
MyGui *m_MyGui;
m_MyGui->setObjectName("Cam 1");
and I use the following to when I need to get the widget
Code:
MyGui *tmp = findChild<MyGui *>("Cam 1");
Any help?
Re: findChild(ObjectName) fails?
From what class are you calling it? If m_MyGui isn't a child of that class, then it is normal for the function to fail.
Re: findChild(ObjectName) fails?
Also make sure MyGui class has the Q_OBJECT macro.
Re: findChild(ObjectName) fails?
Thanks. I get it. This MyGui is not a child of the caller class. Emmm. Need to look for another method of finding an object.
Re: findChild(ObjectName) fails?
Store a pointer somewhere or use signals and slots.
Re: findChild(ObjectName) fails?
Thanks wysota! The method "signal and slot" does the job very well.