Important: Please read the Qt Code of Conduct -

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

  • 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?

  • Qt Champions 2017

    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 . 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.

  • Qt Champions 2017

    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.

Log in to reply