Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem of updating map data in qml(myclient send qml get)



  • main.cpp:
    MyClient receiver;
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/map/MapComponent.qml")));
    QQmlContext* ctx = engine.rootContext();
    ctx->setContextProperty("receiver", &receiver);
    receiver.sendToQml("mainsenddata");

    myclient.h:
    class MyClient : public QObject
    {
    Q_OBJECT
    public:
    explicit MyClient(QObject *parent = 0);
    void SetSocket(int Descriptor);

    signals:
    void sendToQml(QString count);

    public slots:
    void connected();
    void disconnected();
    void readyRead();
    void TaskResult(int Number);

    private:
    QTcpSocket *socket;
    };

    myclient.cpp

    QQmlApplicationEngine engine;
    MyClient receiver;

    QQmlContext* ctx = engine.rootContext();
    ctx->setContextProperty("receiver", &receiver);
    engine.load(QUrl(QStringLiteral("qrc:/map/MapComponent.qml")));
    receiver.sendToQml("myclientsenddata");
    

    MapComponent.qml
    Map {

       id: map
     
       property  var imei:1453     
    

    imei value to which the value sent from myclient.cpp and main.cpp will be synchronized

    Connections{
    target:receiver
    property variant gelen: 10

        onSendToQml: {
           // propertyBinding.valueToQML=count;
            console.log("Received in QML from C++: " + count);
            map.imei=count;
    

    up imei value to which the value sent from myclient.cpp and main.cpp will be synchronized

    While the first value sent from the maine in Connections is assigned to the popup1 imei value in the mapcomponent, the value from myclient cannot be imported into imei and cannot be shown on the map.

        }
    }
    

    MapQuickItem {

        id:burhanbaykal_sokak_basi
        coordinate {
            latitude: 39.403456 
            longitude: 30.011561 
        }
    
        sourceItem: Rectangle { width: 12; height: 12;
            border.width: 2; color: "green"
           border.color: "white"; smooth: true; //radius: 7 //color: "#e41e25";
       }
        MouseArea{
           anchors.fill: parent
           hoverEnabled: true
                onEntered:
                    popup1.open()
            }
    
            Popup {
                id: popup1
                background: Rectangle {
                        implicitWidth: 250
                        implicitHeight: 125
                        border.color: "black"
                        color: "#c8c8c8"  //#30d5c8   a0a0a0  #c8c8c8
                        radius: 5
                    }
                 x: Math.round((parent.width - width) / 50)//100
                 y: Math.round((parent.height - height) / 50)//100
                width: 175
                height: 175
                modal: true
                focus: true
                closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
    
             **//imei value in content item cannot get count value from outside**
                contentItem: Text {
                        text: " Sokak:Burhan Baykal Sokak Başı \n Imei:+map.imei+ \n  Seviye:%35 \n  Sinyal:%95 \n  Batarya Durumu:%43 \n  Konum:39.403456, 30.011561 "
    
    
                }
        }
        opacity: 1.0
        anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2)
    
    }

Log in to reply