I'm using Qt 5.0.2 and QtQuick 2.0 to try building a very simple QML application, displaying tiles.
I want the tiles to be dynamically created with a repeater, interfacing C++.
I found an example on how to do it (MineHunt
), but this example is using QtQuick 1 and Qt 4.7.
Here is my code :
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();
}
}
}
This file imports a folder named tiles
containing another QML file named tile.qml
which contains the following code :
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)
}
}
}
I also have a class which implements methods needed to provide the tiles
model.
It compiles fine but when I run it, I get the following error :
ReferenceError: tile is not defined
What's wrong with my code ?