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. Item on Repeater create and destroy when model changed
Forum Updated to NodeBB v4.3 + New Features

Item on Repeater create and destroy when model changed

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
repeatermodel
5 Posts 2 Posters 3.2k Views 2 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.
  • H Offline
    H Offline
    helenebro
    wrote on last edited by
    #1

    Hi,
    I have a repeater with model given by C++ part. There are several field on this model : "name", "value", ... The field "value" change a lot.
    I have notice all item are destroy and recreate each time model change. Is that serious ? Is an other way to do this ?

    Repeater {
        id:repeater
        model: myApp.data
        Rectangle {
            width: 300
            height: 300
    	border.color:"black"
            Row {
               Text {text:modelData.name}
               Text {text:modelData.value}
    	} 
    	Component.onCompleted: console.log("complete", index)
            Component.onDestruction: console.log("destruction", index)              
        }
    }
    
    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by
      #2

      What is the type of myApp.data? If you make it a proper model, Repeater is able to listen to fine-grained notifiers and act correspondingly. If it's some sort of JS-array/object, Repeater gets a notification that the JS-array changes, but doesn't know what exactly changed. It has to rebuild the entire representation, because it basically corresponds to changing the entire model.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        helenebro
        wrote on last edited by helenebro
        #3

        It's a QJsonArray :

            Q_PROPERTY(QJsonArray data READ data WRITE setData NOTIFY dataChanged)
        

        Do you mean it's better to have a QQmlListProperty<MyObject> with MyObject :

        class MyObject : public QObject
        {
        	Q_OBJECT
        	Q_PROPERTY(QString name READ name NOTIFY nameChanged)
        	Q_PROPERTY(int value READ value NOTIFY valueChanged)
        public :
        	...
        };
        

        Is there an influence over performance of application ?

        jpnurmiJ 1 Reply Last reply
        0
        • H helenebro

          It's a QJsonArray :

              Q_PROPERTY(QJsonArray data READ data WRITE setData NOTIFY dataChanged)
          

          Do you mean it's better to have a QQmlListProperty<MyObject> with MyObject :

          class MyObject : public QObject
          {
          	Q_OBJECT
          	Q_PROPERTY(QString name READ name NOTIFY nameChanged)
          	Q_PROPERTY(int value READ value NOTIFY valueChanged)
          public :
          	...
          };
          

          Is there an influence over performance of application ?

          jpnurmiJ Offline
          jpnurmiJ Offline
          jpnurmi
          wrote on last edited by
          #4

          @helenebro It's better to use either QAbstractItemModel (or any descendant) in C++, or ListModel (or other ready-made models) in QML. Since you have a QJsonArray, you could implement a simple QAbstractListModel around it. Just make sure to emit the appropriate signals by calling beginInsertRows() + endInsertRows() when you insert rows, for instance.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            helenebro
            wrote on last edited by helenebro
            #5

            Ok. Thank you for your answer.
            I never use QAbstractListModel. Do you have some keys to start ?

            What is difference between using QAbstractListModel and QQmlListProperty ?
            In which case is it better to use them ?

            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