QWidget, QTableWidget delete (delete) to dynamically add (new) child controls release memory

1, is mainly used to define the function prototype 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, to achieve the release of (delete) QTableWidget dynamic increase (new) child controls

    qDeleteAll(ui->tableWidget->findChildren<MyComboBox *>());
    qDeleteAll(ui->tableWidget->findChildren<MyDoubleSpinBox *>());
MyComboBox, MyDoubleSpinBox are inherited from QComboBox, QDoubleSpinBox custom class, when the sub-control is another type, or the MyComboBox MyDoubleSpinBox
Modify the type to need to find child controls.

Guess you like

Origin www.cnblogs.com/Vince-Wu/p/12669056.html