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

Maurice Kalinowski Maurice.Kalinowski at qt.io
Tue Jun 19 09:11:09 CEST 2018


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.

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:

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: {

    Button {
        id: publish
         text: qsTr("publish")
        onClicked: {

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180619/97f07220/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-WIP-Qt-Quick-Example-Fix-publishing.patch
Type: application/octet-stream
Size: 2932 bytes
Desc: 0001-WIP-Qt-Quick-Example-Fix-publishing.patch
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180619/97f07220/attachment.obj>

More information about the Interest mailing list