Unsolved 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.
if(!allSubLayouts.empty()) { 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 < allSubLayouts.at(i)->count(); ++j) { QWidget *w = allSubLayouts.at(i)->itemAt(j)->widget(); if(w != NULL) { qDebug() << "The className of the object is " ; qDebug() << allSubLayouts.at(i)->itemAt(j)->widget()->metaObject()->className(); w->setVisible(false); //delete w; } } }
When I run the code, everything except the
QLabel
classnames are displayed in theqDebug
statement.Why doesn't
widget()->metaObject()->className();
produce QLabels? -
@mar0029
It seems okay, but have you tried something simpler likeQObject::findChildren
?QList<QWidget *> items = findChildren<QWidget *>(); foreach (QWidget * item, items) qDebug() << item->metaObject()->className();
Kind regards.