首页 > 其他 > 详细

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

时间:2020-04-09 20:41:53      阅读:346      评论:0      收藏:0      [点我收藏+]

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
修改为需要寻找的子控件的类型即可。

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

原文:https://www.cnblogs.com/Vince-Wu/p/12669056.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!