QWidget,QTableWidget删除(delete)动态添加(new)的子控件释放内存

1、主要使用到的QT函数原型定义:

template 
inline void qDeleteAll(const Container &c)
{
    qDeleteAll(c.begin(), c.end());
}
#if QT_CONFIG(regularexpression)
    template
    inline QList findChildren(const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
    {
        typedef typename std::remove_cv::type>::type ObjType;
        QList list;
        qt_qFindChildren_helper(this, re, ObjType::staticMetaObject,
                                reinterpret_castvoid *> *>(&list), options);
        return list;
    }
#endif // QT_CONFIG(regularexpression)

2、实现 释放(delete)QTableWidget中动态增加(new)的子控件

    qDeleteAll(ui->tableWidget->findChildren());
    qDeleteAll(ui->tableWidget->findChildren());
MyComboBox、MyDoubleSpinBox分别是继承自QComboBox、QDoubleSpinBox的自定义类,当子控件为其他类型时,将MyComboBox 或MyDoubleSpinBox
修改为需要寻找的子控件的类型即可。

你可能感兴趣的:(QWidget,QTableWidget删除(delete)动态添加(new)的子控件释放内存)