您的代码有几个错误:
LauncherComponent.LauncherComponent {
id: launcherComponentId
objectName: "launcherComponent"
height: parent.height
width: parent.width
anchors.centerIn: parent
}
-
另一个错误是,如果要使用
ApplicationWindow
您不应该使用
QQuickView
自从
应用程序窗口
创建顶层,并
QQuickView
同样,你将有2个顶级水平,你正在寻找
QQuickView
但不是在
应用程序窗口
孩子们,所以我建议你修改你的。副本收件人:
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtQml import *
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(QUrl("module/Layout.qml"))
if len(engine.rootObjects()) == 0:
sys.exit(-1)
print(engine.rootObjects()[0].findChild(QObject, 'launcherComponent'))
sys.exit(app.exec_())
也就是说,您必须使用
QQmlApplicationEngine
.