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. QQMLListProperty & append function
Forum Updated to NodeBB v4.3 + New Features

QQMLListProperty & append function

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 3.6k 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #1

    Trying to use the QQMListProperty along with append function. Sample code is here

    return QQmlListProperty<User>(this, 0, &UserList::append_user, 0, 0, 0);

    I'm trying find out when does the append_user function called ? I tried all my ways to see if append_user function is called. Not successful.

    What I'm looking for -
    Readymade sample example to show how append_function is called.

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

    1 Reply Last reply
    3
    • M Offline
      M Offline
      mostefa
      wrote on last edited by mostefa
      #2

      Hi @dheerendra

      I think that your function should be called everytime your adding a QML user object on your .qml file :

      for example if you add :

      user{
      
      },
      user{
      
      }
      

      on your .qml file , append _function should be called two times .

      You can see this example from qt doc:

      http://doc.qt.io/qt-5/qtqml-tutorials-extending-qml-example.html#chapter-5-using-list-property-types

      You can use this example on your Qt creator , and add :

      qDebug() << Q_FUNC_INFO;

      on PIECHART.cpp file , in append_slice function

      then cause in qml file we are using 3 slice qml object like this :

      slices: [
                  PieSlice {
                      anchors.fill: parent
                      color: "red"
                      fromAngle: 0; angleSpan: 110
                  },
                  PieSlice {
                      anchors.fill: parent
                      color: "black"
                      fromAngle: 110; angleSpan: 50
                  },
                  PieSlice {
                      anchors.fill: parent
                      color: "blue"
                      fromAngle: 160; angleSpan: 100
                  }
              ]
      

      you will see that append_slice function is called 3times, you can even add more qml object and see the change.

      Console log:

      QML debugging is enabled. Only use this in a safe environment.
      static void PieChart::append_slice(QQmlListProperty<PieSlice>*, PieSlice*)
      static void PieChart::append_slice(QQmlListProperty<PieSlice>*, PieSlice*)
      static void PieChart::append_slice(QQmlListProperty<PieSlice>*, PieSlice*)
      

      Hope this can help.

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

        cool. Thank you for your answer. While creating the list, it is called. My thinking was that, after creating the list, is there way to append to the list so that append_function is called.

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

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

          @dheerendra
          I am not sure I fully understand what do you mean,

          do you wanna add an element to your list without adding it to your qml file?

          Could you tell us more about what you really wanna do ?

          Thank you

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

            @mostefa In your example slices list is created. I would like to add the PieSlice dynamically to slices. Is it possible ?

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

            1 Reply Last reply
            3
            • M Offline
              M Offline
              mostefa
              wrote on last edited by mostefa
              #6

              @dheerendra As far as i know we can not add elements dynamically inside a list of qqmllistproperty , but maybe other people can help you a little more.

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

                @mostefa You are right. We are in same page. As the QQMLListProperty gets exposed as List to QML. List element in QML is not dynamically modifiable. Documentation was slightly confusing. May we can have bug to update the documentation to correctly reflect what it is.

                Thank you for you support. I appreciate the same.

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

                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