0

qstringlistを含むクラスポインタのq_propertyからqstringlistにアクセスしたい次のコードで問題に直面しています。問題に関連するすべてのコードを追加しました。

player.hpp

このクラスはこれから作成されるプレイヤー向けです


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"};
}

スコア入力.hpp

このクラスは、新しいプレーヤーを作成し、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");

スコア入力.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"
                                    }
                                }
                            }
                        }
                    }
                }
            }

最初のインデックスのみで値を取得しており、他のインデックスでは取得していません。また、スコア モデルに値を割り当てることもできません。 アプリのスクリーンショット

さまざまなプレーヤーのスコアにアクセスして変更したいと考えています。

4

1 に答える 1