PDA

View Full Version : Finding QObjcects in a qApp



rianquinn
5th February 2006, 20:32
In Qt 3, you can query for all of the obejcts in the qApp. This is really helpful for finding pointers to QObjects in plugins.

How do you do this in Qt4. Whenever I run the function findChild, or any of the different versions of it the compiler says that this function doesn't exist in the QObject or qApp.

I guess my question would be, How can I get a QObject pointer to any QObject in the qApp via a QString

Example: If I have a plugin loaded with the name plugin_menu, I would like to be able from any function, and any plugin to be able to get a pointer to the QObject * via a string "plugin_menu"

wysota
5th February 2006, 20:55
Basicly you have a "findChildren" member in QObject and you can use it. But you should query plugins this way, there are other mechanisms for it. Check out QPluginLoader class.

rianquinn
5th February 2006, 22:00
When I call the function findChildren, the compiler says this function doesn't exist.

jacek
5th February 2006, 22:33
When I call the function findChildren, the compiler says this function doesn't exist.
Could you post the exact error message?

orb9
6th February 2006, 13:16
When I call the function findChildren, the compiler says this function doesn't exist.
Seems you're one windows using MSVC6. Check qFindChildren in the docs, findChildren is not supported my MSVC6.

Use


QPushButton *pb;
QWidget *objectToSearch = this;
QList<QPushButton> buttons = qFindChildren<QPushButton*>( this, "nameOfObj" );

or


QPushButton *pb;
QWidget *objectToSearch = this;
QList<QPushButton> buttons = qFindChildren( this, "nameOfObj", pb );

Both are untested, i wrote this from memory.

Hope this helps.