Display C++ output as Qml Delegate’s text

I wanted to show my sensor data on rectangulars and put them into gridView. However, I'm wondering, what I'm doing incorrectly:

import QtQuick 2.0
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQml.Models 2.2


Item {
    id: item1
    Rectangle {
        id: rectangle
        color: "#ffffff"
        anchors.fill: parent
        
        Component.onCompleted: {
            
            gridView.model.append({
                                      myColor: 'orange',
                                      myText: qsTr(mqttClient.message1)//doesnt work
                                  });
            gridView.model.append({
                                      myColor: 'red',
                                      myText: qsTr(mqttClient.message2)//doesnt work too
                                  });
            
        }
        
        GridView {
            id: gridView
            anchors.fill: parent
            
            cellWidth: width/4
            cellHeight: height/3
            
            model: ListModel{}
            
            delegate: Rectangle{
                width: gridView.cellWidth/2
                height: gridView.cellHeight/2
                color: myColor
                Text {
                    text: myText
                    font.pointSize: 20
                }
            }   
        }
    }
}



/*##^##
Designer {
    D{i:0;autoSize:true;height:480;width:640}
}
##^##*/

The showing of data actually works, when I do it just with simple rectangles, but not with the delegates. The output of the function mqttClient.message1 is normal string



Read more here: https://stackoverflow.com/questions/66522836/display-c-output-as-qml-delegates-text

Content Attribution

This content was originally published by Bogdan Khamelyuk at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: