
我正在嘗試重現該範例這裡哪裡的標題頁.qml組件創建兩個標題文本實例即使標題文本type 位於單獨的檔案中(在「組件實例層次結構」部分下)。在 Ubuntu SDK 中,我建立了一個新專案(帶有 C++ 插件的 QML 應用程式 (qmake))。我的主.qml看起來像這樣:
import QtQuick 2.4
import Ubuntu.Components 1.2
import ScopeTesting 1.0
MainView {
objectName: "mainView"
applicationName: "scopetesting.username"
width: units.gu(100)
height: units.gu(75)
Item {
property string title
TitleText {
size: 22
anchors.top: parent.top
}
TitleText {
size: 18
anchors.bottom: parent.bottom
}
}
}
這標題文字.qml看起來像這個例子:
import QtQuick 2.4
import Ubuntu.Components 1.2
import ScopeTesting 1.0
Text {
property int size
text: "<b>" + title + "</b>"
font.pixelSize: size
}
我得到的是一個引用錯誤:
...TitleText.qml:7: ReferenceError: 標題未定義
我在這裡缺少什麼?有人可以幫忙嗎?
答案1
物件不能直接使用其他物件的屬性,除非它們屬於檔案的根物件。
移動property string title
到MainView
或給予 id並透過 idItem
使用。title