According to this, there’s no need to add libraries, since MQTT is a Qt module just add this line in your pro file:
QT += mqtt
To use a Qt module, it must be installed in the Qt lib directory.
First, retrieve the lib directory path executing this command from a terminal:
qmake -query QT_INSTALL_LIBS
Cd into that directory and check if a file called Qt5Mqtt.dll is there: if not, you must build/install the module.
To get the module source code, you can execute this git command:
git clone git://code.qt.io/qt/qtmqtt.git
Once you have the source files, cd into the source files directory containing the file qtmqtt.pro and run these commands:
qmake
make
make install
(you may need administrator privileges for the last one).
After the commands completed successfully, you should be able to see the library in the QT_INSTALL_LIBS directory, and use the module in a Qt project.
In case of compilation issues, open the qtmqtt.pro file with creator, and try to build the library from there, then manually install (copy) it into the QT_INSTALL_LIBS.
上面内容是从stack overflow上找到的。亲测可用
我就做一些注解吧
一个是命令行需要有qt 环境。win下的话有专门配好环境的命令行
然后需要右键以管理员身份运行这个命令行。否则无法进行make install
还有一个注意点是注意版本。git clone之前去官网看一下有哪些分支,
像我的是5.12,所以要加上–branch 5.12