[Interest] How to publish a message in QML with Qtmqtt

Egg Nine eggn1n3 at gmail.com
Sun Jun 17 21:19:24 CEST 2018


Hi all,

I am trying to publish an mqtt message using Qt QML following this example:
https://doc.qt.io/QtMQTT/qtmqtt-quicksubscription-example.html

However, this example only shows how to subscribe to topics while I want to
publish.
I tried to call "publish" from QML like can see in code below but nothing
is sent while console.log shows a -1.

Any thoughts what I am doing wrong? Or does someone has an example?
I can see in my broker log that a connection is made successfully.

    MqttClient {
        id: mqttclient
        port: 1883
        hostname: "localhost"
    }

    Button {
        id: connect
        text: qsTr("Connect")
        onClicked: {
            console.log(mqttclient.connectToHost())
        }
    }

    Button {
        id: publish
         text: qsTr("publish")
        onClicked: {
            console.log(mqttclient.publish("mytopic","mytestmessage"))
        }
    }

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180617/b936a67b/attachment.html>


More information about the Interest mailing list