Finding a child member that is a QPointer

157 Views Asked by At

I am trying to use findChildren to pull a list of parameters from my program. The code is below:

QList<QPointer<TParameter> > theFullParameterList;

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

It compiles fine but but When I go into (this) within debug, there are several member types of QPointer<TParameter> but my theFullParameterList comes up empty. TParameter is a custom class. Is there any way to find the children of that class that are within a QPointer?

1

There are 1 best solutions below

1
On

A couple of questions:

1) Are you sure that such instances of that class is not destroyed when you call findChildren?

2) Are you sure to set the parent to the class instances?

I'm able to populate the QList with the following code:

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();
}

And the output: Size of list: 10