Qt 5.0.2 と QtQuick 2.0 を使用して、タイルを表示する非常に単純な QML アプリケーションを構築しようとしています。
C++ とインターフェイスするリピーターを使用して、タイルを動的に作成したいと考えています。
その方法の例を見つけました ( MineHunt
) が、この例では QtQuick 1 と Qt 4.7 を使用しています。
これが私のコードです:
import QtQuick 2.0
import "tiles"
Rectangle {
width: 360
height: 360
Grid {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
anchors.margins: 5
columns: 3
spacing: 10
Repeater {
id: repeater
model: tiles
delegate: tile
}
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
}
このファイルは、次のコードを含むtiles
という名前の別の QML ファイルを含むという名前のフォルダーをインポートします。tile.qml
import QtQuick 2.0
Rectangle {
id: tile
width: 100
height: 62
color: "#ff0303"
MouseArea {
anchors.fill: parent
onClicked: {
var row = Math.floor(index / 3)
var col = index - (Math.floor(index / 3) * 3)
play(row, col)
}
}
}
tiles
モデルを提供するために必要なメソッドを実装するクラスもあります。
正常にコンパイルされますが、実行すると次のエラーが発生します。
ReferenceError: tile is not defined
私のコードの何が問題になっていますか?