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

Egg Nine eggn1n3 at gmail.com
Thu Jun 21 17:31:46 CEST 2018


Thanks Maurice. I can confirm that the patch does work.
I created a bug report: https://bugreports.qt.io/browse/QTBUG-69066

2018-06-19 9:11 GMT+02:00 Maurice Kalinowski <Maurice.Kalinowski at qt.io>:

> 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.io at qt-project.org>
> *Im Auftrag von *Egg Nine
> *Gesendet:* Sunday, June 17, 2018 9:19 PM
> *An:* interest at 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!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180621/69151ea3/attachment.html>


More information about the Interest mailing list