Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Delete a child of a QQuickItem

Delete a child of a QQuickItem

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 3.3k 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.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by
    #1

    Hi,

    I created a Plot class derived from QQuickItem which displays x vs y plot curves. For the single plot curves I created a PlotCurve class which is also derived from QQuickItem and the plot curves are childs of the Plot object. The Plot object has a vector of pointers to its childs.

    I am wondering how I can reset my Plot Object to its original state. Simply calling delete or deleteLater on the adresses of the plot curves is not working.

    If it was c++ only I would probably delete the whole plot object, and create a new one. But as I instantiate the plot object in qml this is not an option.

    How can I reset my object (remove its childs)?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Not quite clear about the question completed. If you want to delete the child object at QML, if you have identity property of QML object, you can say <id>.destroy() or iterate through the child objects using children property of an item and destroy them.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxwell31
        wrote on last edited by maxwell31
        #3

        Sorry for the unclear question. How would I destroy it from c++? In c++ I got the object vis

             QObject *qmlplotobject = rootObjects.value(0)->findChild<QObject*>("myPlot");
        

        This object has a member QVector<PlotCurve *> _curves, but deleting the curves via

           for(int i=0;i<_curves.size();i++) {
              delete _curves[i];
           }
        

        does not work. The plot curves were created via an add_curve function which calls the creator of PlotCurve (derived vom QQuickItem) which also sets the parent of the PlotCurve to be the Plot object.

        Is there something like a remove children function?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxwell31
          wrote on last edited by
          #4

          Hm,

          I tried to call removeAllChildren in the updatePaintNode function of Plot but it seems that it has no effect

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxwell31
            wrote on last edited by
            #5

            Here my stackoverflow post, where I tried to improve the question: https://stackoverflow.com/questions/50852203/qtquickscene-graph-delete-child-node

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maxwell31
              wrote on last edited by
              #6

              this is what i was looking for:

                for(auto &curve : _curves) {
                    curve->setParent(nullptr);
                    curve->setParentItem(nullptr);
                    curve->deleteLater();
                 }
              
              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