1、主要使用到的QT函數原型定義:
template <typename Container> inline void qDeleteAll(const Container &c) { qDeleteAll(c.begin(), c.end()); }
#if QT_CONFIG(regularexpression) template<typename T> inline QList<T> findChildren(const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const { typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type ObjType; QList<T> list; qt_qFindChildren_helper(this, re, ObjType::staticMetaObject, reinterpret_cast<QList<void *> *>(&list), options); return list; } #endif // QT_CONFIG(regularexpression)
2、實現 釋放(delete)QTableWidget中動態增加(new)的子控件
qDeleteAll(ui->tableWidget->findChildren<MyComboBox *>());
qDeleteAll(ui->tableWidget->findChildren<MyDoubleSpinBox *>());
MyComboBox、MyDoubleSpinBox分別是繼承自QComboBox、QDoubleSpinBox的自定義類,當子控件為其他類型時,將MyComboBox 或MyDoubleSpinBox
修改為需要尋找的子控件的類型即可。