Hello,
I'm writing tiny app. Which has QML ListView and after I adding new element (on different page) want see changes on ListView.
I have QAbstractListModel named ServerListModel with method which inserts new value:
Insert method is called from QML which calls remove method (of QAbstractListModel subclass). getModel() methods passes model to QML ListView.Code:void ServerListModel::insertValue(int k, Host &host) { beginInsertRows(QModelIndex(), k, k); servers.append(host); endInsertRows(); emit dataChanged(); reset(); }
In main.cpp I have qmlRegisterType:Code:void ServerModel::insert(QString title, QString hostname, QString username, QString password, qint32 port ) { Host host = Host(title, hostname, username, port) ; servers.append(host); int val = servers.size() -1 ; model->insertValue(val, host); save() ; } QObject * ServerModel::getModel() { return qobject_cast<QObject*>(model) ; }
The problem is that ListView not changing. After executing beginInsertRows or beginDeleteRows I see what rowCount (of QAbstractListModel) is triggered. But getModel() method not. So any suggestions how to fix this problem ?Code:qmlRegisterType<ServerModel>("lt.ServerModel", 1, 0, "ServerModel");

Reply With Quote

