Send QObject with properties to QML



  • I want to send one, two or more Interface objects to Repeater and use its properties in form. But i have null in modelData

    import QtQuick 2.11
    import Service 1.0
    import QtQuick.Controls 2.11
    import QtQuick.Layouts 1.11
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 240
        Service {
            id: service
        }
        ColumnLayout {
        Text {
            text: service.Text
        }
        Repeater {
            model: service.Interfaces
            delegate: Rectangle {
                color: "#b0dfb0"
                
                height: 80
    	        // inject Interface here or pass its properties to items
                Text {
                    text: "bar"
                }
    	        Text {
    	            text: modelData.Text
    	        }
    	        Repeater {
    	            // ...
    	        }
            }
        }
        }
    }
    
    
    import sys
    from PyQt5.QtWidgets import QApplication, QWidget
    from PyQt5.QtCore import pyqtProperty, QCoreApplication, QObject, QUrl
    from PyQt5.QtQml import qmlRegisterType, QQmlComponent, QQmlEngine
    from PyQt5.QtGui import QGuiApplication
    from PyQt5.QtQml import QQmlApplicationEngine
    
    
    class Controller(QObject):
        @pyqtProperty(str)
        def Text(self):
            return "hello word"+repr(self)
        
    
    class Interface(QObject):
        @pyqtProperty(str)
        def Text(self):
            return "bar"+repr(self)
    
        @pyqtProperty(list)
        def Controllers(self):
            return [Controller() for c in range(2)]
    
    class Service(QObject):
        @pyqtProperty(str)
        def Text(self):
            return "foo"+repr(self)
    
        @pyqtProperty(list)
        def Interfaces(self):
            return [Interface() for i in range(2)]
    
    
    
    
    if __name__ == '__main__':
        qmlRegisterType(Service, 'Service', 1, 0, 'Service')
        qmlRegisterType(Interface, 'Service', 1, 0, 'Interface')
        qmlRegisterType(Controller, 'Service', 1, 0, 'Controller')
    
        app = QGuiApplication(sys.argv)
    
        engine = QQmlApplicationEngine()
        engine.load("view.qml")
        engine.quit.connect(app.quit)
        sys.exit(app.exec_())