ListView的模型数据更改时不会更新

时间:2019-12-19 10:26:39

标签: qt qml

我有一个QList<QObject*>,它是从ListView模块中读入model中的。首先,QList是一个空对象。我希望在向indexBackup对象分配新列表时更新QList

import QtQuick          2.5
import QtQuick.Controls 2.0
import QtQuick.Layouts  1.2
import QtQuick.Controls.Styles 1.0

ListView {
    id: layersListView

    model: settingsList   //QList<QObject*> object
    int indexBackup: 0

    onModelChanged: {
        if(indexBackup && indexBackup < model.length) 
        {
            indexBackup = model.length
        }
        else 
        {
            indexBackup = - 1
        }
    }
}    

1 个答案:

答案 0 :(得分:0)

对于每个有类似问题的人,都可以找到答案here