Hello all,
I'd like to get a list of all (say) QPushButtons in my widget. I can get a list off all child ofjects usingor recursivly using
how do I then test my <T>s to see if they are a specific type, i.e. QPushButtons?
thanks
K
Printable View
Hello all,
I'd like to get a list of all (say) QPushButtons in my widget. I can get a list off all child ofjects usingor recursivly using
how do I then test my <T>s to see if they are a specific type, i.e. QPushButtons?
thanks
K
Just as it says in the docs:
Quote:
QList<T> QObject::findChildren ( const QString & name = QString() ) const
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. An empty string matches all object names. The search is performed recursively.
The following example shows how to find a list of child QWidgets of the specified parentWidget named widgetname:
QList<QWidget *> widgets = parentWidget.findChildren<QWidget *>("widgetname");
This example returns all QPushButtons that are children of parentWidget:
QList<QPushButton *> allPButtons = parentWidget.findChildren<QPushButton *>();
Warning: This function is not available with MSVC 6. Use qFindChildren() instead if you need to support that version of the compiler.
ahh, yes, got it. (sorry)
I was having some trouble with the syntax.
For the MSVC people:
works perfectly.Code:
QList<QPushButton*> btnList = qFindChildren<QPushButton*> ( this, "" );
and there's also
Code:
QList<QPushButton*> btnList = qFindChildren<QPushButton*> ( this );
much appreciated
K