首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查找作为QPointer的子成员

查找作为QPointer的子成员
EN

Stack Overflow用户
提问于 2014-09-17 10:35:22
回答 1查看 122关注 0票数 0

我正在尝试使用findChildren从我的程序中提取参数列表。代码如下:

代码语言:javascript
复制
QList<QPointer<TParameter> > theFullParameterList;

foreach(TParameter *child, this->findChildren<TParameter* >())
{
    theFullParameterList << QPointer<TParameter>(child);
}

它编译得很好,但是当我在debug中进入(这个)时,有几个QPointer<TParameter>的成员类型,但是我的theFullParameterList是空的。TParameter是一个自定义类。有没有办法找到在QPointer中的那个类的子类

EN

回答 1

Stack Overflow用户

发布于 2014-09-17 11:32:49

有几个问题:

1)您确定调用findChildren时该类的实例不会被销毁吗

2)确定设置类实例的父类吗?

我可以用以下代码填充QList

代码语言:javascript
复制
MainWindow::MainWindow()
{
    for (int i = 0; i < 10; i++)
        new TParameter(this);
}

void MainWindow::on_pushButton_clicked()
{
    QList<QPointer<TParameter>> theFullParameterList;

    foreach(TParameter *child, findChildren<TParameter*>())
        theFullParameterList << QPointer<TParameter>(child);

    qDebug() << "Size of list:" << theFullParameterList.size();
}

输出:Size of list: 10

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25881374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档