i have some simple hierarchy of widgets
looks something like this :
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(423, 479);
MainWindow->setLayoutDirection(Qt::LeftToRight);
MainWindow->setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
horizontalLayout = new QHBoxLayout(centralwidget);
horizontalLayout->setSpacing(0);
horizontalLayout->setContentsMargins(0, 0, 0, 0);
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
StreamViewWidget = new StreamView(centralwidget);
StreamViewWidget->setObjectName(QString::fromUtf8("StreamViewWidget"));
horizontalLayout_2 = new QHBoxLayout(StreamViewWidget);
horizontalLayout_2->setSpacing(0);
horizontalLayout_2->setContentsMargins(0, 0, 0, 0);
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
streamList = new StreamList(StreamViewWidget);
streamList->setObjectName(QString::fromUtf8("streamList"));
streamList->setStyleSheet(QString::fromUtf8("background-color: rgb(171, 251, 255);"));
horizontalLayout_2->addWidget(streamList);
horizontalLayout->addWidget(StreamViewWidget);
MainWindow->setCentralWidget(centralwidget);
menubar = new QMenuBar(MainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 423, 22));
MainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
now StreamViewWidget and streamList; are promoted , and i have there class
now from StreamViewWidget i want get access to streamList.
so i try to do this but it fails and im getting empty result .
StreamView::StreamView(QWidget *parent) :QWidget(parent)
{
pStreamList = this->findChild<StreamList*>("streamList");
QList<StreamList *> widgets = this->findChildren<StreamList *>("streamList");
}
also when i do in StreamView QObject::dumpObjectTree()
im getting : so i guess its not a child of StreamView , but how can i get the streamList?
QWidget::centralwidget
QHBoxLayout::horizontalLayout
StreamView::
any idea what im doing wrong here ?
Thanks
When you call
the
horizontalLayout2becomes the parent ofstreamList. The parent ofhorizontalLayout2isStreamViewWidget, andStreamViewWidgetis NOT the parent ofstreamList. Does that makes sense?But all that is besides the point. The reason why it’s not working is probably because you are trying to find the child of a widget that doesn’t exist yet. You are in the constructor of
StreamView, remember?