QT installs the mqtt environment (here default and with QT)

    First of all, the version of QT and the version of the mqtt package should be consistent (the versions of QT and mqtt here are both 5.14.2)

        QT installation package (5.14.2) download address: Index of /archive/qt/5.14

      A link to the mqtt package (you can choose the corresponding version)  GitHub - qt/qtmqtt at 5.14.2

 After decompressing the mqtt package, open mqtt.pro with QTCREATOR and compile with release.

An error may occur during compilation: “QtMqtt/qmqttglobal.h”: No such file or directory

Copy all the header files under the src source code folder in the mqtt package to the include/mqtt folder under the QT installation package directory to solve the problem.

After the build is successful, there are the following steps:

  1. Copy all the files in lib in the mqtt package component directory to the lib folder of the corresponding QT compiler

 2. Copy the files under the bin folder in the mqtt package component directory to the bin folder corresponding to the QT compiler

 3. Copy the files under the modules or modules-inst folder under the mkspecs folder in the mqtt package component directory to the corresponding directory of the QT compiler

 4. Copy the examples\mqtt\simpleclient folder in the mqtt package to the project directory (that is, copy a copy for experiment), find it, and add the mqtt module. Change the contents of the pro file to this.

Then change the mainwindow.h header file to this and then no error will be reported

Then click Run and an interface will appear

  

Officially provided two test addresses, test.mosquitto.org and broker.hivemq.com), you can also use your own address. Here are some tests:

State Change0 means waiting

State Change2 means connected.

5. Conduct a QT project of my own for testing

Double-click the .pro file in the project to open the project and click configure project

This error is reported after clicking build

  The reason is that this path is wrong. The correction method is to copy the lib folder under the mingw73_64 folder in the QT installation package (of course it can also be other folders such as mingw73_32) to the project (lib folder) and then copy it according to the storage location. The path to this folder (lib folder).

        The statement LIBS += H:\MqttTest\lib\lib*.a under the .pro file of this QT changes the wrong path to the path of this folder (LIBS += D:\QTcode\led\MqttTest1\ lib\lib*.a) (my path) and build again. Here I choose 64-bit and build build is release. Then run it directly and it will come out

They all succeeded! ! !

Give a free triple! ! !

Guess you like

Origin blog.csdn.net/qq_51243202/article/details/130944365