⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

MQTT- How to implement it, with Qt?

  • Can someone point me to Qt or any external resources|example to implement MQTT Publisher, Broker, Subscriber.

  • Lifetime Qt Champion

    Maybe you can use an existing client ?

  • Hi @Muzab
    MQTT implementation is provided through C++ classes, So all its possible to implement it.
    Here is sample code [link MQTT](link https://github.com/eclipse/mosquitto).
    If not i can share other sample code.

  • @mrjj

    This is the first time I am using a git project to be added into the library. Unfortunately! it does'nt work if I just compile it or run it.

    I cannot import

    #include <qmqtt.h>

    Can you tell me what more is to be done here ? Thanks!

  • Lifetime Qt Champion


    If you are using Qt Creator then you can use the technique described here

  • @SGaist :

  • Hi, Muzab. Did you fix this problem, can you show me how please? i'm new to qmqtt and have the same problem.

  • Hi @DoNgocTuan
    There is nothing like QMQTT , mqtt is a opensource , can be cross compiled and can be added as external library.

    Steps to Compile,Configre,Run,Test the Mosquitto MQTT Broker.

    1. Download the Mosquitto MQTT Broker Source code from the following URL and Extract it:
      $ wget http://mosquitto.org/files/source/mosquitto-1.4.2.tar.gz
      $ tar -xvf mosquitto-1.4.2.tar.gz

    2.Install the Dependency Libraries:
    sudo apt-get install libssl-dev libwrap0-dev libc-ares-dev uuid-dev

    3.Now go to the mosquitto-1.4.2 directory:

    Run the following Commands:

    $ make all
    $ sudo make install
    $ sudo ldconfig

    4.Now Mosquitto
    o has Sucessfully compiled and

    Include Path : /usr/local/include
    Library Path : /usr/local/lib
    Binary Path : /usr/local/bin

    In bin you will have the following Binaries:
    mosquitto_passwd mosquitto_pub mosquitto_sub

    5.Now start the mosquitto broker

    $ mosquitto
    1437720047: mosquitto version 1.4.2 (build date 2015-07-24 12:04:19+0530) starting
    1437720047: Using default config.
    1437720047: Opening ipv4 listen socket on port 1883.
    1437720047: Opening ipv6 listen socket on port 1883.

    6.Test the mosquitto broker.

    Open two terminal windows.
    In the first terminal run

    $ mosquitto_sub -h -t myTopic

    In the second terminal run

    $ mosquitto_pub -h -t myTopic -m "My first message"

    At this point, on the first terminal you should have received the message “My first message”

    7.Now test the Qt Application by Runing Respective Binaries.

    First run ./MosquittoSubscribe and subscribe to a topic.
    Now Run ./MosquittoPublish and Publish to same topic.

  • Lifetime Qt Champion

    @yuvaram Sure there is: qmqtt from the Erlang MQTT project.

  • thank you @SGaist

Log in to reply