metaObject()->className() doesn't find QLabel

  • Hello!

    I am using the following code to find all QLayouts within a main layout and then all widgets within those layouts.

        int size = allSubLayouts.size();
        for(int i = 0; i < size; i ++)  // this loop hides all of the layouts that are currently present. If there are no layouts, nothing happens
            for(int j = 0; j <>count(); ++j)
                QWidget *w =>itemAt(j)->widget();
                if(w != NULL)
                    qDebug() << "The className of the object is " ;
                    qDebug() <<>itemAt(j)->widget()->metaObject()->className();
                    //delete w;

    When I run the code, everything except the QLabel classnames are displayed in the qDebug statement.

    Why doesn't widget()->metaObject()->className(); produce QLabels?

  • Moderators

    It seems okay, but have you tried something simpler like QObject::findChildren?

    QList<QWidget *> items = findChildren<QWidget *>();
    foreach (QWidget * item, items)
        qDebug() << item->metaObject()->className();

    Kind regards.

Log in to reply