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. Strange bug/quirk with QObject's dumpObjectTree()
Forum Updated to NodeBB v4.3 + New Features

Strange bug/quirk with QObject's dumpObjectTree()

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 362 Views
  • 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.
  • devDawgD Offline
    devDawgD Offline
    devDawg
    wrote on last edited by
    #1

    Hello all,
    Was not sure if I should post this here or in the QML section, but I encountered something strange while exploring the object tree of a QObject.

    Essentially, I create a QQmlComponent from my qml file that holds all my formatting. I then create a QObject pointer object from this component. The purpose of this is so I can dig through its object tree to find a LineSeries embedded within a ChartView delegate, allowing me to link data refresh signals with new data points being added to my graph.

    What's strange, is that when I grab the ListView from the object tree (it is title "chartListView") and dump its object tree, I see another QObject titled "chartListView" in its object tree!! So either I am not doing something correctly, or I have discovered a bug.. I will post code below.

    main.cpp:

     QQmlComponent sumPage(&engine,QUrl("qrc:/Display0.qml"));
    
        QObject *summaryPage = sumPage.create(); //access to entire Display0.qml file
        graphList->setQMLReference(summaryPage);
    
    

    setQMLReference method inside the graphList object:

    void GraphModel::setQMLReference(QObject *comp)
    {
        QObject *ref = new QObject();
        QObjectList *items = new QObjectList(comp->findChildren<QObject *>(QString()));
    
        for (int i = 0; i < items->length();i++) {
    
            if (items->at(i)->objectName().compare(QString("chartListView"),Qt::CaseSensitive)) {
                ref = items->at(i);
                qDebug() << "found it.";
                qDebug() << ref->metaObject()->className();
                qDebug() << "obj tree: "; ref->dumpObjectTree();
                qDebug() << "obj info: "; ref->dumpObjectInfo();
                break;
            }
        }
        items = new QObjectList(ref->findChildren<QObject *>(QString()));
        for (int i = 0; i < items->length();i++) {
            qDebug() << items->at(i)->objectName();
            qDebug() << items->at(i)->metaObject()->className();
        }
    }
    

    here is the ListView section of Display0.qml:

    ListView {
                            objectName: "chartListView"
                            id: chartListView
                            x: 0
                            y: 130
                            width: 350
                            height: 350
    
                            anchors.top: controlRect.bottom
                            orientation: Qt.Vertical
    
                            /*
                                Procedure:
                                -load a DataPiece in to GraphModel. (name, units, value, maximum, minimum)
                                -Set up ChartView & LineSeries according to that DataPiece.
                             */
    
                            model: graphModel.getSize()
    
                            delegate: ChartView {
                                objectName: "chartView"
                                width: 350
                                height: 350
                                title: graphModel.getDataAt(index).getModuleName() + " " + graphModel.getDataAt(index).getName() + " vs. time"
    
                                LineSeries {
    
    
                                    axisX: ValueAxis {
                                        objectName: "xAxis"
                                        color: "black"
                                        gridVisible: true
                                        labelsFont.pointSize: 5
                                        titleFont.pointSize: 8
                                        titleText: "time (s)"
                                        visible: true
                                        min: 0
                                    }
                                    axisY: ValueAxis {
                                    min: graphModel.getDataAt(index).minimumAsInt()
                                    max: graphModel.getDataAt(index).maximumAsInt()
                                    objectName: "yAxis"
                                    color: "black"
                                    gridVisible: true
                                    labelsFont.pointSize: 5
                                    titleFont.pointSize: 8
                                    titleText: graphModel.getDataAt(index).getName() + " (" + graphModel.getDataAt(index).getUnits() + ")"
                                    visible: true
                                    }
                                    /*x vals come from this timer. When the first value change of the DataPiece is detected, x=0 is used for the first
                                    point, the timer is started, and timer values are used for x values from then on.
                                    */
                                    Timer {
                                        id: objTimer
                                        objectName: graphModel.getDataAt(index).getName() + "Timer"
    
                                    }
    
                                //must implement C++ logic to add data points here.
    
                                }
                            }
                        }
    

    Finally, some console output to show you what I am talking about:

    found it.
    QQuickRectangle
    obj tree: 
    QQuickRectangle:: 
        QQuickSwipeView:: 
    
    
    
    
            QQmlObjectModel:: 
            QQuickListView:: 
                QQuickItem:: 
    
    
                    QQuickItem:: 
            QQuickItem:: 
                QQuickRectangle::chartRect 
                    QQuickRectangle:: 
                    QQuickListView::chartListView 
                        QQuickItem:: 
                            QQuickItem:: 
                        QQmlComponent:: 
                QQuickRectangle::rightRect 
                    QQuickListView:: 
                        QQuickItem:: 
                            QQuickText:: 
                                QQmlContext:: 
                                QQuickListViewAttached:: 
                            QQuickItem:: 
                        QQmlComponent:: 
                        QQmlComponent:: 
                QQmlObjectModelAttached:: 
                QQuickListViewAttached:: 
            QQuickItem:: 
                QQuickButton:: 
                    QQuickRectangle:: 
                    QQuickText:: 
                QQmlObjectModelAttached:: 
                QQuickListViewAttached:: 
        QQuickPageIndicator:: 
            QQuickRow:: 
                QQuickRepeater:: 
            QQmlComponent::
    

    To recap, I have a LineSeries inside of a graph that I want to synchronize with data being fed into the system, with as quick of a refresh rate as possible. That being said, I am well aware that I may not be achieving my goal the most efficient way possible, and would be open to other suggestions.

    But the main question is, why am I seeing "chartListView" inside the Object tree of "chartListView"?

    Anything worthwhile is never achieved easily.

    devDawgD 1 Reply Last reply
    0
    • devDawgD devDawg

      Hello all,
      Was not sure if I should post this here or in the QML section, but I encountered something strange while exploring the object tree of a QObject.

      Essentially, I create a QQmlComponent from my qml file that holds all my formatting. I then create a QObject pointer object from this component. The purpose of this is so I can dig through its object tree to find a LineSeries embedded within a ChartView delegate, allowing me to link data refresh signals with new data points being added to my graph.

      What's strange, is that when I grab the ListView from the object tree (it is title "chartListView") and dump its object tree, I see another QObject titled "chartListView" in its object tree!! So either I am not doing something correctly, or I have discovered a bug.. I will post code below.

      main.cpp:

       QQmlComponent sumPage(&engine,QUrl("qrc:/Display0.qml"));
      
          QObject *summaryPage = sumPage.create(); //access to entire Display0.qml file
          graphList->setQMLReference(summaryPage);
      
      

      setQMLReference method inside the graphList object:

      void GraphModel::setQMLReference(QObject *comp)
      {
          QObject *ref = new QObject();
          QObjectList *items = new QObjectList(comp->findChildren<QObject *>(QString()));
      
          for (int i = 0; i < items->length();i++) {
      
              if (items->at(i)->objectName().compare(QString("chartListView"),Qt::CaseSensitive)) {
                  ref = items->at(i);
                  qDebug() << "found it.";
                  qDebug() << ref->metaObject()->className();
                  qDebug() << "obj tree: "; ref->dumpObjectTree();
                  qDebug() << "obj info: "; ref->dumpObjectInfo();
                  break;
              }
          }
          items = new QObjectList(ref->findChildren<QObject *>(QString()));
          for (int i = 0; i < items->length();i++) {
              qDebug() << items->at(i)->objectName();
              qDebug() << items->at(i)->metaObject()->className();
          }
      }
      

      here is the ListView section of Display0.qml:

      ListView {
                              objectName: "chartListView"
                              id: chartListView
                              x: 0
                              y: 130
                              width: 350
                              height: 350
      
                              anchors.top: controlRect.bottom
                              orientation: Qt.Vertical
      
                              /*
                                  Procedure:
                                  -load a DataPiece in to GraphModel. (name, units, value, maximum, minimum)
                                  -Set up ChartView & LineSeries according to that DataPiece.
                               */
      
                              model: graphModel.getSize()
      
                              delegate: ChartView {
                                  objectName: "chartView"
                                  width: 350
                                  height: 350
                                  title: graphModel.getDataAt(index).getModuleName() + " " + graphModel.getDataAt(index).getName() + " vs. time"
      
                                  LineSeries {
      
      
                                      axisX: ValueAxis {
                                          objectName: "xAxis"
                                          color: "black"
                                          gridVisible: true
                                          labelsFont.pointSize: 5
                                          titleFont.pointSize: 8
                                          titleText: "time (s)"
                                          visible: true
                                          min: 0
                                      }
                                      axisY: ValueAxis {
                                      min: graphModel.getDataAt(index).minimumAsInt()
                                      max: graphModel.getDataAt(index).maximumAsInt()
                                      objectName: "yAxis"
                                      color: "black"
                                      gridVisible: true
                                      labelsFont.pointSize: 5
                                      titleFont.pointSize: 8
                                      titleText: graphModel.getDataAt(index).getName() + " (" + graphModel.getDataAt(index).getUnits() + ")"
                                      visible: true
                                      }
                                      /*x vals come from this timer. When the first value change of the DataPiece is detected, x=0 is used for the first
                                      point, the timer is started, and timer values are used for x values from then on.
                                      */
                                      Timer {
                                          id: objTimer
                                          objectName: graphModel.getDataAt(index).getName() + "Timer"
      
                                      }
      
                                  //must implement C++ logic to add data points here.
      
                                  }
                              }
                          }
      

      Finally, some console output to show you what I am talking about:

      found it.
      QQuickRectangle
      obj tree: 
      QQuickRectangle:: 
          QQuickSwipeView:: 
      
      
      
      
              QQmlObjectModel:: 
              QQuickListView:: 
                  QQuickItem:: 
      
      
                      QQuickItem:: 
              QQuickItem:: 
                  QQuickRectangle::chartRect 
                      QQuickRectangle:: 
                      QQuickListView::chartListView 
                          QQuickItem:: 
                              QQuickItem:: 
                          QQmlComponent:: 
                  QQuickRectangle::rightRect 
                      QQuickListView:: 
                          QQuickItem:: 
                              QQuickText:: 
                                  QQmlContext:: 
                                  QQuickListViewAttached:: 
                              QQuickItem:: 
                          QQmlComponent:: 
                          QQmlComponent:: 
                  QQmlObjectModelAttached:: 
                  QQuickListViewAttached:: 
              QQuickItem:: 
                  QQuickButton:: 
                      QQuickRectangle:: 
                      QQuickText:: 
                  QQmlObjectModelAttached:: 
                  QQuickListViewAttached:: 
          QQuickPageIndicator:: 
              QQuickRow:: 
                  QQuickRepeater:: 
              QQmlComponent::
      

      To recap, I have a LineSeries inside of a graph that I want to synchronize with data being fed into the system, with as quick of a refresh rate as possible. That being said, I am well aware that I may not be achieving my goal the most efficient way possible, and would be open to other suggestions.

      But the main question is, why am I seeing "chartListView" inside the Object tree of "chartListView"?

      devDawgD Offline
      devDawgD Offline
      devDawg
      wrote on last edited by
      #2

      @devDawg fixed it, I'm an idiot... In my QString compare() method where I check objectNames to equal "chartListView", I didn't make it equal to 0! Simple fix.

      Anything worthwhile is never achieved easily.

      1 Reply Last reply
      4

      • Login

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