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).
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:
For this, en every .h file:
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:
- Download source code from https://github.com/qt/qtmqtt (pay attention to your Qt version)
- Extract the zip and open the root .pro project with Qt Creator and navigate to src .h files
- Remove all the necessary <QtMqtt/ prefixes in order the routes to be recognized and fix the path errors presented on .h files
- Compile for your current kit (in our case, Windows 7 64 MSVC 2015 Community Edition 64 bits Qt 5.12.2)
- Copy the .h files and lib directory to your local lib path
- 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
- In your code, you can include the library classes as follow:
#include <qmqttclient.h>
-
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 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
-
@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:
- I opened the Qt console and navigate to the path and executed the qmake and make commands that you described:
- qmake seems to be valid:
-
But make is not:
-
So I tried with mingw32-make and get the following error:
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.
-
I downloaded and extracted the 5.12.2 Mqtt version corresponding to my Qt working version.
-
I opened the root level .pro file
- I configured with the Qt 5.12.2 MSVC2015 64bit version:
- I get the following errors:
- If i try to build the project, I get the following errors:
6. After the previous errors, I first execute qmake from Qt Creator (Build -> Run qmake) and seems to work fine with no errors:- I build again but the original errors remain:
Please, any idea?
Thanks
-
-
Do you have perl installed on your machine ?
-
Which version of perl do you have ?
-
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:
For this, en every .h file:
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:
- Download source code from https://github.com/qt/qtmqtt (pay attention to your Qt version)
- Extract the zip and open the root .pro project with Qt Creator and navigate to src .h files
- Remove all the necessary <QtMqtt/ prefixes in order the routes to be recognized and fix the path errors presented on .h files
- Compile for your current kit (in our case, Windows 7 64 MSVC 2015 Community Edition 64 bits Qt 5.12.2)
- Copy the .h files and lib directory to your local lib path
- 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
- 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...