Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
6.8
-
None
Description
When there is a need to find children of many types in a row, it would be handy to have just one function, like:
template <T...>
QList<QObject *> QObject::findChildren() const;
that would return a QList<QObject *> (instead of QList<T>) for a passed list of children types T....
Motivation:
- This would be more optimal to get the common list during just one traversal.
- This would be more handy to have all results in one common list and the code repetition could be easily avoided.
Currently, one needs to do:
const QList<QComboBox *> comboChildren = widget->findChildren<QComboBox *>(); for (auto child : comboChildren) { // process child } const QList<QAbstractSpinBox *> spinChildren = widget->findChildren<QAbstractSpinBox *>(); // 2nd lookup for (auto child : spinChildren) { // code repetition // process child } // Can't easily merge comboChildren and spinChildren lists into one common list, since they are of different types.
Use case: setWheelScrollingWithoutFocusBlockedForChildren in https://codereview.qt-project.org/c/qt-creator/qt-creator/+/512132
Possible additional feature: Make the return type of the QList<T> customizable. E.g. in the example above, we might want to get the QList<QWidget *> as a return type. This might be an additional template parameter type. Alternatively, maybe it could be automatically deduced as a common denominator of all types passed as T... template parameter