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. How to remove or update the C++ model fed qml components
Forum Updated to NodeBB v4.3 + New Features

How to remove or update the C++ model fed qml components

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

    Hello, I have C++ model fed qml components in the Grid view. The qml component is delegate in the Gridview. I do not know how to remove the qml components if the C++ model is changed, members removed or also added?

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

      Just look at the custom model examples in example directly. Model is structurally modified. You may need to call beginInsertRows(..) & endInsertRow().. like function. This will auto update your grid view.

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

      M 1 Reply Last reply
      0
      • dheerendraD dheerendra

        Just look at the custom model examples in example directly. Model is structurally modified. You may need to call beginInsertRows(..) & endInsertRow().. like function. This will auto update your grid view.

        M Offline
        M Offline
        milan
        wrote on last edited by milan
        #3

        @dheerendra . Thank you for your reply. I created Q_INVOKABLE method in C++ and called this function in qml, this did remove the C++ model item. Because, the qml afterwards produced error as it is now connected to value of undefined. But the qml component is not removed from the UI, yet the C++ model is removed. Also inside the Q_INVOKABLE method, I called

                emit dataChanged(item, item);
        

        Because now I know that the model has been changed, but eht change is not reflected in the UI.

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

          only this signal will not help. Please note this is dataChanged() signal. It is applicable only if you change the data. In your case you are removing the elements. It means that your structurally modifying the model. Please look at beginInsert(..) endInsert(..) method. Look at the examples in the directory quickcontrols2/contactlist/contactmodel.cpp. It should help you.

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

          1 Reply Last reply
          2

          • Login

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