PDA

View Full Version : QML, Refer to a rectangle that is repeated by Repeater, to change the text



nilhcraiv
13th November 2011, 23:44
Hi all, I have this code in QML is a grid of 40x40 pixels square, and each displays text "¿...?", when click on a square it changes the text according funcion.checkPos (index). My problem is that apart from changing the text of each square with one click, I need to modify the text of each square after receive signal from Qt. The signal is perfectly connected to the code QML and it is emited correctly.

From main.cpp I connect the signal with slot of QML

QObject::connect(&Clase,SIGNAL(nuevaPalabra()),rootObject,SLOT(modif icarTexto()));

This is a QML code with the slot modificarTexto():

function modificarTexto(palabra) { texto.text = palabra}

Rectangle{
id: rectangulo1
pos.x: 0; pos.y: 0
width: 641; height: 401;
Grid {
x: 1; y: 1
rows: 10; columns: 16; spacing: 1
Repeater {
id: repeticion
model: 160
Rectangle {
id: rectangulo2
width: 39; height: 39
color: "blue"
Text {
id: texto
text: "¿...?"
font.pointSize: 10
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
texto.text = Clase.checkPos(index);
}
}
}
}
}
}

The problem is in the slot modificarTexto, since, QtCreator shows that texto.text does not refer to anything or not found it, i.e. no references found, How can I to do reference individually to the text of each square, since, it is repeated the same square with Repeater? How do I indicate that the text shall it changes after recieve the signal from Qt? I don't know how to do reference a square determinate of the grid.

I hope someone has the answer!
Thanks in advance