Qt Quck와 Qt5/PyQt를 처음 접했고 이상한 문제에 직면했습니다. 아래의 QML 정의에서 objectName "test"가있는 객체를 찾으려고합니다.QObject :: findChild()는 명백한 이유없이 None을 반환합니다.
self.rootObject().findChild(QObject, "test")
그러나이 호출은 None을 반환합니다. 그러나 objectName: "test"
속성을 상위 Tab 요소로 이동하면 성공적으로 발견됩니다. 그것은 단지 어린이의 내부에서 whemm을 발견하지 않고있다 Item
. 마찬가지로 addChannel
, modifyChannel
및 removeChannel
개체도 findChild()
에 의해 발견되지 않습니다.
import QtQuick 2.0
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.1
import "TouchStyles"
Item {
ListModel { }
TouchButtonFlatStyle { id: touchButtonFlat }
TouchTabViewStyle { id: touchTabView }
Rectangle {
width: 480
height: 230
TabView {
currentIndex: 0
tabPosition: 1
anchors.fill: parent
style: touchTabView
Tab {
title: "Play"
Item {
anchors.fill: parent
PianoKeyboard { anchors.centerIn: parent }
}
}
Tab {
title: "Channels"
Item {
objectName: "test"
ListView {
anchors.fill: parent
model: listModel
delegate: Channel {}
}
BorderImage {
border.bottom: 8
anchors.bottom: parent.bottom
source: "images/toolbar.png"
width: parent.width
height: 50
RowLayout {
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
Button { text: "Add"; objectName: "addChannel" }
Button { text: "Modify"; objectName: "modifyChannel" }
Button { text: "Remove"; objectName: "removeChannel" }
}
}
}
}
}
}
}
내가 뭘 잘못하고 있니? Qt 문서는 검색이 재귀 적으로 수행된다고 말합니다. 왜 전체 객체 트리를 가로 지르지 않습니까?
가장 좋은 방법은 먼저 C++에서 검색이 성공했는지 확인하는 것입니다. 그렇지 않으면 Qt 버그로보고하십시오. 그렇지 않으면 PyQt 버그가됩니다. –
'self.rootObject(). findChildren (QObject)'(모든 자식)의 결과는 무엇입니까? –
첫 번째 탭에서 동일한 작업이 수행됩니까 (두 번째 탭의 항목을 첫 번째 탭으로 복사하는 경우)? 또는 findChild를 수행하기 전에 두 번째 탭을 선택하면 같은 문제가 발생합니까? – Schollii