PDA

View Full Version : findChild(ObjectName) fails?



Ran
19th January 2008, 14:49
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

MyGui *m_MyGui;
m_MyGui->setObjectName("Cam 1");

and I use the following to when I need to get the widget


MyGui *tmp = findChild<MyGui *>("Cam 1");

Any help?

marcel
19th January 2008, 17:16
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.

wysota
19th January 2008, 18:12
Also make sure MyGui class has the Q_OBJECT macro.

Ran
19th January 2008, 22:39
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.

wysota
20th January 2008, 11:19
Store a pointer somewhere or use signals and slots.

Ran
21st January 2008, 06:58
Thanks wysota! The method "signal and slot" does the job very well.