QT 4.5
QList <QObject*> widgets=this->children();
QListIterator <QObject *> i(widgets);
while(i.hasNext())
{
QCheckBox chkbox=(QCheckBox*)i.next();
}
QT 3.5
窗口中的所有按钮失效(QObjectList 类在qobjectlist.h 头文件中被定义):
QObjectList *l = topLevelWidget()->queryList( "QButton" );
QObjectListIt it( *l ); // 遍历按钮
QObject *obj;
while ( (obj = it.current ()) != 0 ) {
// 对于每一个找到的对象……
++it;
((QButton*)obj)->setEnabled( FALSE );
}
delete l; // 删除这个列表,而不是对象
void * qt_find_obj_child ( QObject * parent, const char * type, const char * name )
返回一个继承了parent 对象类型为type 的名为name 的对象的指针。
如果没有这样的对象,返回0。
QListBox *c = (QListBox *) qt_find_obj_child ( myWidget, "QListBox",
"my list box" );
if ( c )
c->insertItem ( "another string" );