Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

[SOLVED] PyQt5 connect to QML (Question)



  • hi guys
    i have this error in connecting PyQt5 to QML :
    QQmlComponent: Component is not ready
    (i really need this connection)
    i have this program (please guide me and tell me my mistakes):
    @# Filename: pythonSide2.py
    import sys

    from PyQt5.QtCore import pyqtProperty, QCoreApplication, QObject, QUrl
    from PyQt5.QtQml import qmlRegisterType, QQmlComponent, QQmlEngine

    class ConnectToQml(QObject):

    def __init__(self, parent=None):
        super(ConnectToQml, self).__init__(self)
        self._var = "Hello"
    
    @pyqtProperty('QString')
    def variable(self):
        return self._var
    

    app = QCoreApplication(sys.argv)
    qmlRegisterType(ConnectToQml, 'CQ', 1, 0, 'ConnectToQml')

    engine = QQmlEngine()
    component = QQmlComponent(engine)
    component.loadUrl(QUrl('qmlSide2.qml'))

    person = component.create()@
    and
    @// Filename: qmlSide2.qml
    import QtQuick 2.0
    import CQ 1.0

    Rectangle {
    width: 400
    height: 400
    Text {
    id: myText
    text: connectToQml.variable
    anchors.horizontalCenter: parent.horizontalCenter
    }
    ConnectToQml {
    id: connectToQml
    }
    }@


Log in to reply