Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get widget from other widget , when findChild dosnt work , using promoted class
Forum Updated to NodeBB v4.3 + New Features

How to get widget from other widget , when findChild dosnt work , using promoted class

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 4.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    hi
    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mohsen
      wrote on last edited by
      #2

      At the first step you should check for Why "findChild" doesn't work? Maybe the reason is conflicts between names on your object creation and where you're finding that object name.
      @streamList->setObjectName(QString::fromUtf8("streamList"));@
      then
      @pStreamList = this->findChild<StreamList*>("streamList");@ shouldn't be like this? @pStreamList = this->findChild<StreamList*>(QString::fromUtf8("streamList"));@

      and other solution is passing the object's pointer to the other widget and you'll have direct access to your widget.

      However using same names for object name and the class name would be a problem itself!

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        Class name and object name can be the same, it does not matter.

        You can see, whether the streamList is in the child list at all:

        @
        foreach(const QObject *obj, this->children()) {
        qDebug() << obj;
        }
        @

        Check if the streamList is in the debug output.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved