I'm facing issue with the following code where I want to access a qstringlist from q_property of the class pointer containing the qstringlist. I have added all the code relevant to the problem.
player.hpp
This class is for players which will be created
class Player : public QObject {
Q_OBJECT
Q_PROPERTY(QStringList score READ score WRITE setScore NOTIFY scoreChanged)
QStringList m_score = {"9", "2", "3", "4", "5", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4"};
}
scoreinput.hpp
This class creates new players and append to the m_playerList.
class ScoreInput : public QObject
{
Q_OBJECT
Q_PROPERTY(QList<Player *> playerList READ playerList WRITE setPlayerList NOTIFY playerListChanged)
QList<Player *> m_playerList;
}
main.cpp
qmlRegisterType<ScoreInput>("Score", 1, 0, "Score");
qmlRegisterType<Player>("Player", 1, 0, "Player");
scoreinput.qml
Row{
width: 4 * (0.15625) * item_ScorecardScreen2.width //200
height: (0.618) * item_ScorecardScreen2.height //432
Repeater{
id:repeater_Player
model: scoreInput.playerList
// model: 1
Component.onCompleted: {
console.log(repeater_Player.model)
}
Column {
id: column3
width: (0.15625) * item_ScorecardScreen2.width //200
height: (0.618) * item_ScorecardScreen2.height //432
Repeater{
id:repeater_3
model: modelData.score
Rectangle{
id:rect_Col3
width: (0.15625) * item_ScorecardScreen2.width //200
height: (0.103) * item_ScorecardScreen2.height //72
color: "#F2F2F2"
border.color: "#C5C5C5"
TextField {
id: text3
color: "#2A2A2A"
// text: scorecard.player1Score[index]
text: modelData
placeholderText: "-"
anchors.fill: parent
font.pixelSize: (0.0121) * (item_ScorecardScreen2.width + item_ScorecardScreen2.height )
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter //24
font.family: "Roboto"
font.weight: Font.Medium
maximumLength: 1
readOnly: index == 18 ? true : false
selectByMouse : readOnly
validator: IntValidator {
bottom:0
top: 9
}
Component.onCompleted: {
console.log(text3.text)
}
onEditingFinished: {
// scorecard.player1Score[index] = text3.text
modelData = text3.text
console.log("Score Added")
}
inputMethodHints: Qt.ImhFormattedNumbersOnly
background: Rectangle {
anchors.fill: parent
color: "#F2F2F2"
border.color: "#C5C5C5"
}
}
}
}
}
}
}
I'm getting only value at the first index only and not the other index. And I'm also not able to assign values for the score model. Screenshot of the app
I want to access and change the scores for different players.