Important: Please read the Qt Code of Conduct -

Add MQTT module to QT project

  • I am trying to add MQTT functionality in a QT project (based on QGroundControl).
    Just as in this case: How can i add module mqtt to QT? , I am trying to use the QMQTT library. The solution proposed at the aforementioned thread do not seem to work for me (I am using windows).
    I did the following:

    1. added the qmqtt lib folder to E:\QGC\Stable_V4.0\libs
    2. added the command "add_subdirectory(qmqtt)" to the project's CMakeLists.txt
    3. added "#include "qmqtt.h"" to main.c
    4. added the line "QT += mqtt"

    I constantly get the error "Project ERROR: Unknown module(s) in QT: mqtt"

    Any help would be appreciated.

  • Lifetime Qt Champion

    @gampo said in Add MQTT module to QT project:


    Is that your Qt installation or why do you add qmqtt there?

  • Thank you very much for responding, let alone so quickly.
    I assumed the project's libs folder should contain all the used libraries, so I added the downloaded lib folder to the project's one.
    Apologies if this is a newbie mistake...

    P.S. took many minute for me to respond due to my being new to the forum and thus having a mandatory 10-minute delay between posts.

  • Lifetime Qt Champion

    @gampo You need to add MQTT to your Qt installation to be able to build applications using it.
    Also: 2 and 4 indicate that you're mixing CMake and QMake? So, which one do you want to use?

  • Are you aware of the installation path to which MQTT should be added?
    I assume it must be E:\Qt\5.15.0\Src\qttools\src, right?
    Also , should I add the entire library folder (containing the CMakeLists files etc) or just the folder containing the .h, .cpp, .pro and .pri files?

    As for points 2 and 4, you are right, I mixed things up... I will delete the CMakeList command and only use QMake from at the projects .pro file.

  • Lifetime Qt Champion

    @gampo You should first explain what exactly you're trying to install. What did you actually download exactly?
    Usually you would download source code and do:

    mkdir build_qmqtt
    cd build_qmqtt
    PATH_TO_YOUR_QMAKE ../qmqtt_src
    make install

    "make install" would install everything needed in your Qt installation.

  • @jsulm
    I downloaded the entire qmqtt repository containing:

    1. an "examples" subfolder
    2. a "src" subfolder containing an "mqtt" sub-subfolder
    3. a "test" subfolder

    All the .h and .cpp files are inside the mqtt sub-subfolder.
    I am on windows so I can sadly not follow the linux installation process...

  • Lifetime Qt Champion

    @gampo Then you first need to build it. What I posted is not really Linux instructions. You have to do the same on Windows also. Use the command prompt from MinGW or MSVC (what ever you're using). make will be either nmake.exe (MSVC) or mingw32-make.exe (MinGW).

  • I opened a MSVC terminal and directed to E:\QtMQTT\qmqtt\build_qmqtt, but can't proceed after that point...

    Typing "NMAKE: E:\QtMQTT\qmqtt\src gives "'NMAKE:' is not recognized as an internal or external command, operable program or batch file".
    I am really sorry, I lack the experience with such environments.

    Edit: I made a pastebin with the folder tree if it helps at all:

  • Lifetime Qt Champion

    @gampo said in Add MQTT module to QT project:

    Typing "NMAKE: E:\QtMQTT\qmqtt\src gi

    First, call qmake.
    There must not be : after nmake:

    nmake install

Log in to reply