【发布时间】:2018-08-11 05:59:30
【问题描述】:
我看到其他人问这个问题,但我尝试过的都没有奏效。 我正在使用 PyQt 5.10.1。
这里是python代码:
app = QGuiApplication(sys.argv)
view = QQuickView()
view.setSource(QUrl("module/Layout.qml"))
print(view.rootContext())
print(view.findChild(QObject, 'launcherComponent'))
import pdb; pdb.set_trace()
sys.exit(app.exec())
这是 QML 代码:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Window 2.2
import "calendar/resources" as CalendarComponent
import "weather/resources" as WeatherComponent
import "launcher/resources" as LauncherComponent
import Test 1.0
import Weather 1.0
import Calendar 1.0
import Launcher 1.0
ApplicationWindow {
id: appId
width: Screen.desktopAvailableWidth
height: Screen.desktopAvailableHeight
visible: true
modality: Qt.ApplicationModal
flags: Qt.Dialog
title: qsTr("NarcisseOS")
color: "black"
LauncherComponent.LauncherComponent {
id: launcherComponentId
objectName: launcherComponent
height: parent.height
width: parent.width
anchors.centerIn: parent
}
}
我想尽了一切办法。但是这个 findChild 函数只返回 None。
我尝试重新安装 PyQt5。我试图将 objectName 属性放在一个 Rectangle 对象中,我想也许一个更通用的对象会起作用。一个都没用。
【问题讨论】: