Hi, You seem to be perfectly right that publishing does not work out of the box. This is mostly because of a failing auto-conversion from QString to QMqttTopicName.
The easiest workaround is to apply attached patch, which adds a publish using a QString and do the conversion manually. Feel free to create a bugreport, so that we can take this into consideration when adding a proper qml api for this module. BR, Maurice Kalinowski Von: Interest <interest-bounces+maurice.kalinowski=qt...@qt-project.org> Im Auftrag von Egg Nine Gesendet: Sunday, June 17, 2018 9:19 PM An: interest@qt-project.org Betreff: [Interest] How to publish a message in QML with Qtmqtt 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!
0001-WIP-Qt-Quick-Example-Fix-publishing.patch
Description: 0001-WIP-Qt-Quick-Example-Fix-publishing.patch
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest