Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can I use the QtMqtt code?



  • Re: How can i add module mqtt to QT?

    Hi,

    I tried to follow the indications in the link above, but I am not able to compile and use the official QtMqtt source code placed in https://github.com/qt/qtmqtt.

    As shown in the following screenshot, I'm using the Qt Creator because the Qt console didn't work neither. My setup: Windows 7 - MSVC2015 - Qt 5.12. I opened the code and tried to execute qmake and build in the .pro files inside (not sure what were the correct one).

    0_1552560738283_0d84c92a-82eb-4183-aa9c-fcb526fd7823-image.png

    I know this is a basic question, but, how can I integrate the available QtMqtt source code to my own project? I really would appreciate some indications.

    Thanks!!



  • @JoeBermejales HI, finally I modified the source code and it works!! I removed the QtMqtt/ in the includes as shown in the following screenshots:

    I changed this:
    0_1553072624291_baa7a81b-9c50-43ff-818d-ba51a274468b-image.png

    For this, en every .h file:
    0_1553072682284_aebd950b-4ec6-4c82-a85d-d7b4999be662-image.png

    And now it compiles!!!

    Thanks to @SGaist and @Pablo-J-Rogina for your help! :)

    I summarize here the way I achieved to compile and use the official Mqtt source code in Windows 7 Pro:

    1. Download source code from https://github.com/qt/qtmqtt (pay attention to your Qt version)
    2. Extract the zip and open the root .pro project with Qt Creator and navigate to src .h files
    3. Remove all the necessary <QtMqtt/ prefixes in order the routes to be recognized and fix the path errors presented on .h files
    4. Compile for your current kit (in our case, Windows 7 64 MSVC 2015 Community Edition 64 bits Qt 5.12.2)
    5. Copy the .h files and lib directory to your local lib path
    6. Add the following code to your .pro file (correct the relative routes if necessary)
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/mqtt/lib/ -lQt5Mqtt
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/mqtt/lib/ -lQt5Mqttd
    INCLUDEPATH += $$PWD/mqtt/src
    DEPENDPATH += $$PWD/mqtt/src
    win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/mqtt/lib/Qt5Mqtt.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/mqtt/lib/Qt5Mqttd.lib
    
    1. In your code, you can include the library classes as follow:
    #include <qmqttclient.h>
    

  • Lifetime Qt Champion

    Hi,

    If you use Qt 5.12, you'll already have the module with Qt so no need to build it by hand.

    The Qt Creator About Box doesn't give the information about what version of Qt you are using but from the looks of it, you have Qt 5.12.2.



  • @SGaist thanks you for the instant response! but I get the following error:

    0_1552562738470_3e9b83b1-0866-4300-ac47-4885d4c2d628-image.png

    0_1552562792494_6873923e-1c15-4b49-ac0b-65f4a0913db9-image.png

    Does this apply to my current config (MSVC2015 - Qt12.2.2 - W7 ) ??

    0_1552562859504_10f7d603-4c58-48a4-b7cd-f971b4d0d16a-image.png



  • @SGaist said in How can I use the QtMqtt code?:

    you'll already have the module with Qt so no need to build it by hand.

    Qt MQTT is not part of "standard" Qt 5.12 distribution... From documentation:

    Note: Qt MQTT is part of the Qt for Automation offering and not Qt. For further details please see Qt for Automation.

    @JoeBermejales have you try building the module from command line?, like this:

    git clone git://code.qt.io/qt/mqtt.git -b 5.12
    cd mqtt
    qmake
    make
    make install
    

  • Lifetime Qt Champion

    @Pablo-J-Rogina Good catch ! I forgot about that.



  • @Pablo-J.-Rogina said in How can I use the QtMqtt code?:

    @JoeBermejales have you try building the module from command line?, like this:

    Yes, but I get some errors. I did the following:

    • I downloaded the qtmqtt 5.11.2 branch (corresponding to my Qt current version -in previous question and setup it was 5.12.2, but get the same error-) and extracted to the following path:

    0_1552654365460_c8129aeb-494e-4175-a7fe-efd4eafd5902-image.png

    • I opened the Qt console and navigate to the path and executed the qmake and make commands that you described:

    0_1552654459379_f7274d56-d30c-4891-843c-12e2d1fd84b1-image.png

    0_1552654563937_9ea85648-709f-4fd7-a58d-b047b247996c-image.png

    • qmake seems to be valid:

    0_1552654583199_f7bbf2a5-e3e5-4fd4-be00-e8178cf2372b-image.png

    • But make is not:
      0_1552654642478_f5e0f45d-936e-4ccf-96f5-b3914259535e-image.png

    • So I tried with mingw32-make and get the following error:

    0_1552654724704_d93f8f4c-0049-4087-bfca-105620859eb8-image.png

    
    C:\Qt\5.11.2\mingw53_32\qtmqtt-5.11.2\qtmqtt-5.11.2>mingw32-make
    cd src\ && ( if not exist Makefile C:\Qt\5.11.2\mingw53_32\bin\qmake.exe -o Makefile C:\Qt\5.11.2\mingw53_32\qtmqtt-5.11
    .2\qtmqtt-5.11.2\src\src.pro ) && mingw32-make -f Makefile
    mingw32-make[1]: Entering directory 'C:/Qt/5.11.2/mingw53_32/qtmqtt-5.11.2/qtmqtt-5.11.2/src'
    cd mqtt\ && ( if not exist Makefile C:\Qt\5.11.2\mingw53_32\bin\qmake.exe -o Makefile C:\Qt\5.11.2\mingw53_32\qtmqtt-5.1
    1.2\qtmqtt-5.11.2\src\mqtt\mqtt.pro ) && mingw32-make -f Makefile
    mingw32-make[2]: Entering directory 'C:/Qt/5.11.2/mingw53_32/qtmqtt-5.11.2/qtmqtt-5.11.2/src/mqtt'
    mingw32-make -f Makefile.Release all
    mingw32-make[3]: Entering directory 'C:/Qt/5.11.2/mingw53_32/qtmqtt-5.11.2/qtmqtt-5.11.2/src/mqtt'
    g++ -c -fno-keep-inline-dllexport -msse2 -mstackrealign -mfpmath=sse -O2 -std=c++1y -fno-exceptions -Wall -W -Wextra -Wv
    la -Wdate-time -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DWINVER=0x0601 -D_WIN32_WINNT=0x0601 -DQT_NO_NARRO
    WING_CONVERSIONS_IN_CONNECT -DQT_BUILD_MQTT_LIB -DQT_BUILDING_QT -D_CRT_SECURE_NO_WARNINGS -D_USE_MATH_DEFINES -DQT_NO_C
    AST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPR
    ECATED_BEFORE=0x040800 -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I..\..\include -I..\..\inclu
    de\QtMqtt -IC:/Qt/5.11.2/mingw53_32/qtmqtt-5.11.2/qtmqtt-5.11.2/include/QtMqtt/5.11.2 -IC:/Qt/5.11.2/mingw53_32/qtmqtt-5
    .11.2/qtmqtt-5.11.2/include/QtMqtt/5.11.2/QtMqtt -Itmp -IC:\Qt\5.11.2\mingw53_32\include -IC:\Qt\5.11.2\mingw53_32\inclu
    de\QtNetwork -IC:\Qt\5.11.2\mingw53_32\include\QtCore\5.11.2 -IC:\Qt\5.11.2\mingw53_32\include\QtCore\5.11.2\QtCore -IC:
    \Qt\5.11.2\mingw53_32\include\QtCore -I.moc\release -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -I
    C:\Utils\postgresql\pgsql\include -IC:\Qt\5.11.2\mingw53_32\mkspecs\win32-g++  -o .obj\release\qmqttclient.o qmqttclient
    .cpp
    In file included from qmqttclient.cpp:30:0:
    qmqttclient.h:33:32: fatal error: QtMqtt/qmqttglobal.h: No such file or directory
    compilation terminated.
    Makefile.Release:571: recipe for target '.obj/release/qmqttclient.o' failed
    mingw32-make[3]: *** [.obj/release/qmqttclient.o] Error 1
    mingw32-make[3]: Leaving directory 'C:/Qt/5.11.2/mingw53_32/qtmqtt-5.11.2/qtmqtt-5.11.2/src/mqtt'
    Makefile:40: recipe for target 'release-all' failed
    mingw32-make[2]: *** [release-all] Error 2
    mingw32-make[2]: Leaving directory 'C:/Qt/5.11.2/mingw53_32/qtmqtt-5.11.2/qtmqtt-5.11.2/src/mqtt'
    Makefile:40: recipe for target 'sub-mqtt-make_first' failed
    mingw32-make[1]: *** [sub-mqtt-make_first] Error 2
    mingw32-make[1]: Leaving directory 'C:/Qt/5.11.2/mingw53_32/qtmqtt-5.11.2/qtmqtt-5.11.2/src'
    Makefile:42: recipe for target 'sub-src-make_first' failed
    mingw32-make: *** [sub-src-make_first] Error 2
    
    C:\Qt\5.11.2\mingw53_32\qtmqtt-5.11.2\qtmqtt-5.11.2>
    

    Any idea what is going on?

    Thanks for your help



  • @JoeBermejales maybe this post I did some time ago should help.

    It looks like you need to ask qmake to recurse subdirs with the -r argument.



  • @Pablo-J.-Rogina thank you, but after following the suggested instructions nothing seems to work, and I had multiple errors, so I started from the beginning with Qt Creator.

    1. I downloaded and extracted the 5.12.2 Mqtt version corresponding to my Qt working version.
      0_1552911676522_1e5722ec-2812-418a-8a95-f7ff1825b5ae-image.png

    2. I opened the root level .pro file

    0_1552911770125_27356426-832a-4046-a549-b6e181b2942e-image.png

    1. I configured with the Qt 5.12.2 MSVC2015 64bit version:

    0_1552911810756_b45da8da-83fa-4bb3-bd25-929da28dd9ac-image.png

    1. I get the following errors:

    0_1552911850606_b02db119-9b47-4439-a8e3-e07f078a71d9-image.png

    1. If i try to build the project, I get the following errors:

    0_1552911934174_ca6c93c8-e16f-46fb-ae77-2a87bbcad061-image.png
    6. After the previous errors, I first execute qmake from Qt Creator (Build -> Run qmake) and seems to work fine with no errors:

    0_1552912087070_82aaf512-2edd-4cad-9a18-edd5e329f46a-image.png

    1. I build again but the original errors remain:
      0_1552912196214_a335324e-07bc-49a0-9947-6bf951a6a6c0-image.png

    Please, any idea?

    Thanks


  • Lifetime Qt Champion

    Do you have perl installed on your machine ?



  • @SGaist yes, and I tried to reinstall Qt 5.12.2 with Mingw 7.3.0 64bits and get the same errors:

    0_1553006226110_e07b43fb-5441-4876-8158-cca84068f1f5-image.png

    I will try in another computer, we really need the QtMqtt code to communicate to a remote device.

    Thanks again @SGaist


  • Lifetime Qt Champion

    Which version of perl do you have ?



  • @SGaist

    perl -v
    
    This is perl 5, version 26, subversion 3 (v5.26.3) built for MSWin32-x64-multi-thread
    (with 2 registered patches, see perl -V for more detail)
    
    perl -V
    
    Summary of my perl5 (revision 5 version 26 subversion 3) configuration:
    
      Platform:
        osname=MSWin32
        osvers=6.1.7601
        archname=MSWin32-x64-multi-thread
        uname=''
        config_args='undef'
        hint=recommended
        useposix=true
        d_sigaction=undef
        useithreads=define
        usemultiplicity=define
        use64bitint=define
        use64bitall=undef
        uselongdouble=undef
        usemymalloc=n
        default_inc_excludes_dot=define
        bincompat5005=undef
      Compiler:
        cc='C:\PROGRA~1\MINGW-~1\X86_64~1.0-W\mingw64\bin\gcc.exe'
        ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DU
    SE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fwrapv -fno-strict
    -aliasing -mms-bitfields'
        optimize='-s -O2'
        cppflags='-DWIN32'
        ccversion=''
        gccversion='4.6.3'
        gccosandvers=''
        intsize=4
        longsize=4
        ptrsize=8
        doublesize=8
        byteorder=12345678
        doublekind=3
        d_longlong=define
        longlongsize=8
        d_longdbl=define
        longdblsize=16
        longdblkind=3
        ivtype='long long'
        ivsize=8
        nvtype='double'
        nvsize=8
        Off_t='long long'
        lseeksize=8
        alignbytes=8
        prototype=define
      Linker and Libraries:
        ld='C:\PROGRA~1\MINGW-~1\X86_64~1.0-W\mingw64\bin\g++.exe'
        ldflags ='-s -static-libgcc -static-libstdc++ -L"C:\Perl64\lib\CORE" -L"C:\M
    inGW\x86_64-w64-mingw32\lib"'
        libpth=C:\MinGW\x86_64-w64-mingw32\lib
        libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32
     -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion
     -lodbc32 -lodbccp32 -lcomctl32
        perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladva
    pi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lver
    sion -lodbc32 -lodbccp32 -lcomctl32
        libc=
        so=dll
        useshrplib=true
        libperl=libperl526.a
        gnulibc_version=''
      Dynamic Linking:
        dlsrc=dl_win32.xs
        dlext=dll
        d_dlsymun=undef
        ccdlflags=' '
        cccdlflags=' '
        lddlflags='-mdll -s -static-libgcc -static-libstdc++ -L"C:\Perl64\lib\CORE"
    -L"C:\MinGW\x86_64-w64-mingw32\lib"'
    
    
    Characteristics of this binary (from libperl):
      Compile-time options:
        HAS_TIMES
        HAVE_INTERP_INTERN
        MULTIPLICITY
        PERLIO_LAYERS
        PERL_COPY_ON_WRITE
        PERL_DONT_CREATE_GVSV
        PERL_IMPLICIT_CONTEXT
        PERL_IMPLICIT_SYS
        PERL_MALLOC_WRAP
        PERL_OP_PARENT
        PERL_PRESERVE_IVUV
        USE_64_BIT_INT
        USE_ITHREADS
        USE_LARGE_FILES
        USE_LOCALE
        USE_LOCALE_COLLATE
        USE_LOCALE_CTYPE
        USE_LOCALE_NUMERIC
        USE_LOCALE_TIME
        USE_PERLIO
        USE_PERL_ATOF
        USE_SITECUSTOMIZE
      Locally applied patches:
        ActivePerl Build 2603 [a95bce075]
        f79ab36645 win32: Fix installsitebin and installsitescript entries in Config
    _heavy.pl
      Built under MSWin32
      Compiled at Dec 17 2018 09:46:45
      @INC:
        C:/Perl64/site/lib
        C:/Perl64/lib
    

    Edit: I tried in another computer (W7 64bits - Mingw 5.3.0 - Qt 5.11.2) and same error: QtMqtt/qmqttglobal.h file not found



  • @JoeBermejales HI, finally I modified the source code and it works!! I removed the QtMqtt/ in the includes as shown in the following screenshots:

    I changed this:
    0_1553072624291_baa7a81b-9c50-43ff-818d-ba51a274468b-image.png

    For this, en every .h file:
    0_1553072682284_aebd950b-4ec6-4c82-a85d-d7b4999be662-image.png

    And now it compiles!!!

    Thanks to @SGaist and @Pablo-J-Rogina for your help! :)

    I summarize here the way I achieved to compile and use the official Mqtt source code in Windows 7 Pro:

    1. Download source code from https://github.com/qt/qtmqtt (pay attention to your Qt version)
    2. Extract the zip and open the root .pro project with Qt Creator and navigate to src .h files
    3. Remove all the necessary <QtMqtt/ prefixes in order the routes to be recognized and fix the path errors presented on .h files
    4. Compile for your current kit (in our case, Windows 7 64 MSVC 2015 Community Edition 64 bits Qt 5.12.2)
    5. Copy the .h files and lib directory to your local lib path
    6. Add the following code to your .pro file (correct the relative routes if necessary)
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/mqtt/lib/ -lQt5Mqtt
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/mqtt/lib/ -lQt5Mqttd
    INCLUDEPATH += $$PWD/mqtt/src
    DEPENDPATH += $$PWD/mqtt/src
    win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/mqtt/lib/Qt5Mqtt.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/mqtt/lib/Qt5Mqttd.lib
    
    1. In your code, you can include the library classes as follow:
    #include <qmqttclient.h>
    


  • I tried the same but I got the error:

    $ make
    cd src/ && ( test -e Makefile || C:/Qt/5.14.2/mingw73_64/bin/qmake.exe -o Makefile "C:/Users/Leander Schulten/git_projects/Lichtsteuerung.git/src/lib/qtmqtt/mqtt/src/src.pro" ) && make -f Makefile
    make[1]: Entering directory '/c/Users/Leander Schulten/git_projects/Lichtsteuerung.git/src/lib/qtmqtt/mqtt/src'
    cd mqtt/ && ( test -e Makefile || C:/Qt/5.14.2/mingw73_64/bin/qmake.exe -o Makefile "C:/Users/Leander Schulten/git_projects/Lichtsteuerung.git/src/lib/qtmqtt/mqtt/src/mqtt/mqtt.pro" ) && make -f Makefile
    Could not find a sync.profile for 'C:/Users/Leander'
    Project MESSAGE: perl -w C:\Qt\5.14.2\mingw73_64\bin\syncqt.pl -module QtMqtt -version 5.14.2 -outdir "C:/Users/Leander Schulten/git_projects/Lichtsteuerung.git/src/lib/qtmqtt/mqtt" -builddir "C:/Users/Leander Schulten/git_projects/Lichtsteuerung.git/src/lib/qtmqtt/mqtt" C:/Users/Leander Schulten/git_projects/Lichtsteuerung.git/src/lib/qtmqtt/mqtt
    Project ERROR: Failed to run: perl -w C:\Qt\5.14.2\mingw73_64\bin\syncqt.pl -module QtMqtt -version 5.14.2 -outdir "C:/Users/Leander Schulten/git_projects/Lichtsteuerung.git/src/lib/qtmqtt/mqtt" -builddir "C:/Users/Leander Schulten/git_projects/Lichtsteuerung.git/src/lib/qtmqtt/mqtt" C:/Users/Leander Schulten/git_projects/Lichtsteuerung.git/src/lib/qtmqtt/mqtt
    make[1]: *** [Makefile:50: sub-mqtt-make_first] Error 3
    make[1]: Leaving directory '/c/Users/Leander Schulten/git_projects/Lichtsteuerung.git/src/lib/qtmqtt/mqtt/src'
    make: *** [Makefile:52: sub-src-make_first] Error 2
    

    My username contains a space and this created a problem as you can see here: Could not find a sync.profile for 'C:/Users/Leander' <- should be 'Leander Schulten'



  • @autoantwort said in How can I use the QtMqtt code?:

    My username contains a space and this created a problem

    Avoid the problem using a path without spaces in it...


Log in to reply