对于一个使用MQTT的项目,我总是必须从源代码编译QtMqtt模块,因为它没有包含在预构建的windows版本中,也不能被选择安装。在Qt5中,这非常容易:从官方git (https://code.qt.io/cgit/qt/qtmqtt.git/)下载源代码,在QtCreator中打开.pro文件并编译项目。对于安装,我只是将.dll文件移到Qt目录中。
现在,在Qt6中,构建过程从qmake切换到cmake,所以我不能简单地在QtCreator中加载项目,而是必须使用CMake手动编译它,我发现这确实是不直观的,而且容易出错。据我所知,从现在开始,我不能单独编译单个模块,而是必须获得整个QT6.2.0源代码(即通过安装程序选项),然后在CMake上使用一个CMake选项来构建特定的模块。所以我到目前为止所做的是:
Qt/6.2.0/Src)Qt/6.2.0/build)..\Src\configure -prefix Qt\6.2.0\buildcmake --build . --target qtmqtt使用cmake构建cmake --install .安装所发生的情况是,配置工作正常,构建也正常,但是安装失败,如下所示:
CMake Error at qtbase/src/3rdparty/libpng/cmake_install.cmake:41 (file):
file INSTALL cannot find
"F:/DEV/prog/Qt/6.2.0/build/qtbase/mkspecs/modules/qt_ext_libpng.pri": File
exists.
Call Stack (most recent call first):
qtbase/src/3rdparty/cmake_install.cmake:42 (include)
qtbase/src/cmake_install.cmake:42 (include)
qtbase/cmake_install.cmake:244 (include)
cmake_install.cmake:42 (include)然后,文件夹Qt/6.2.0/build只包含.cmake文件,而不是任何对我来说似乎有用的.dll文件。我只是不明白如何用cmake正确地设置所有的东西。为什么现在它们会使它变得如此复杂,因为在Qt5中用qmake编译模块相当容易?
发布于 2022-04-24 00:05:52
使用Qt安装程序在${HOME}/Qt/6.4.0/中安装QT6.4.0,这就是我在Linux上所做的工作。
详细步骤:
# Create a work directory
mkdir ~/temporal && cd ~/temporal
# Clone the repository
git clone https://github.com/qt/qtmqtt.git
# Switch to the repository
cd qtmqtt
# Checkout the branch corresponding to the target kit
git checkout 6.4.0
# Create a directory to build the module cleanly
mkdir build && cd build
# Use the qt-configure-module tool
~/Qt/6.4.0/gcc_64/bin/qt-configure-module ..
# Build it here
~/Qt/Tools/CMake/bin/cmake --build .
# Install the module in the correct location
~/Qt/Tools/CMake/bin/cmake --install . --verbose在清洁项目上进行测试:
CMakeLists.txt 编辑项目的文件
(1)将Mqtt添加到相关的find_package宏中,如下所示:
find_package(QT NAMES Qt6 COMPONENTS Widgets Network Sql Mqtt REQUIRED)(2)将Qt${QT_VERSION_MAJOR}::Mqtt添加到如下target_link_libraries行:
target_link_libraries(MyCleanProject PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Mqtt Qt${QT_VERSION_MAJOR}::Sql)(3)运行CMake
实际上尝试使用模块
在项目源代码中添加相关内容如下:
#include <QtMqtt/QtMqtt>
// and then try to use QtMqtt classes
QMqttClient client;重建项目。应该干净地编译和链接.
https://stackoverflow.com/questions/68928310
复制相似问题