I'm pretty new to PyQt5 and QML integration. I've been searching a long time about that problem and I can't find a scenario close enough to my case.
The error I'm having is the following(I'm using PyCharm):
File "D:/PyCharmProjects/SimpleQML.py", line 13, in __init__
self.win = self.root.findChild(QObject, "mainWindow")AttributeError: 'NoneType' object has no attribute 'findChild'
Here is my python code:
import sys
from PyQt5.QtCore import QUrl, QObject
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQuick import QQuickView
class SimpleQML(QQuickView):
def __init__(self, parent=None):
super(SimpleQML, self).__init__(parent)
self.setSource(QUrl.fromLocalFile("D:/Qt/SimpleQML/SimpleQML.qml"))
self.root = self.rootObject()
self.win = self.root.findChild(QObject, "mainWindow")
if __name__ == '__main__':
app = QApplication(sys.argv)
win = SimpleQML()
win.setTitle("SimpleQML")
win.setResizeMode(QQuickView.SizeRootObjectToView)
win.show()
sys.exit(app.exec_())
Here is my (really simple) QML code:
import QtQuick 2.6
import QtQuick.Window 2.2
Rectangle{
id: mainWindow
objectName: "mainWindow"
visible: true
width: 400
height: 400
color: "#323232"
}
And if you have any advice concerning the integration of QML with PyQt5 it's more than welcome.
Thank you in advance!