<div dir="ltr"><div>Hi</div><div><br></div><div>If QAbstractItemModel registered in qml and created in qml, it is not possible to</div><div>use same model in two or more lists, because item inserting cause multiple signal</div><div>propagation to lists.</div><div><br></div><div>I've done example:</div><div><br></div><div>Python script:</div><div><br></div><div><div>import sys</div><div>from PyQt5.QtCore import QUrl</div><div>from PyQt5.QtWidgets import QApplication</div><div>from PyQt5.QtQuick import QQuickView</div><div>from PyQt5.QtCore import QAbstractItemModel</div><div>from PyQt5.QtQml import qmlRegisterType</div><div>from PyQt5.QtCore import Qt</div><div>from PyQt5.QtCore import pyqtSlot</div><div>from PyQt5.QtCore import QModelIndex</div><div><br></div><div>class ExampleModel(QAbstractItemModel):</div><div><br></div><div> def __init__(self, parent, **kwargs):</div><div> super().__init__(parent=parent, **kwargs)</div><div> self.row_count = 0</div><div><br></div><div> def rowCount(self, index):</div><div> return self.row_count</div><div><br></div><div> @pyqtSlot(int, name='doInsert')</div><div> def do_insert(self, count):</div><div> self.beginInsertRows(QModelIndex(), self.row_count, self.row_count+count-1)</div><div> self.row_count += count</div><div> self.endInsertRows()</div><div><br></div><div> def index(self, row, col, index):</div><div> return self.createIndex(row, col)</div><div><br></div><div> def roleNames(self):</div><div> return {Qt.UserRole: b'value'}</div><div><br></div><div> def data(self, index, role=Qt.DisplayRole):</div><div> if index.row() < self.row_count:</div><div> return 'Correct index'</div><div> return 'Wrong index'</div><div><br></div><div>if __name__ == '__main__':<br></div><div> myApp = QApplication(sys.argv)<br></div><div> qmlRegisterType(ExampleModel, "EXAMPLE.Models", 1, 0, "ExampleModel")<br></div><div> content = QQuickView()<br></div><div> content.setSource(QUrl('example.qml'))</div><div> content.show()<br></div><div> myApp.exec_()<br></div><div> sys.exit()</div></div><div><br></div><div>example.qml:</div><div><br></div><div><div>import EXAMPLE.Models 1.0</div><div>import QtQuick.Controls 1.4</div><div>import QtQuick 2.6</div><div><br></div><div>Item {</div><div> width: 600</div><div> height: 500</div><div><br></div><div> ExampleModel {</div><div> id: exampleModel</div><div> }</div><div> Column {</div><div> Row{</div><div> ListView {</div><div> width: 200</div><div> height: 300</div><div> model: exampleModel</div><div> delegate: Text {</div><div> text: value</div><div> }</div><div> }</div><div> ListView {</div><div> width: 200</div><div> height: 300</div><div> model: exampleModel</div><div> delegate: Text {</div><div> text: value</div><div> }</div><div> }</div><div> }</div><div><br></div><div> Button {</div><div> text: "click me"</div><div> onClicked: exampleModel.doInsert(1)</div><div> }</div><div> }</div><div>}</div></div><div><br></div><div><br></div><div>I think there is error in QPyQmlObjectProxy::connectNotify - every</div><div>time when ListView connects to QPyQmlObjectProxy it duplicates</div><div>connection to proxied model, as result proxied model's signal invokes</div><div>connection more than one time.</div><div><br></div><div>thanks</div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Ilya Volkov<br><a href="mailto:nxsofsys@gmail.com" target="_blank">nxsofsys@gmail.com</a></div>
</div>