如何在CMake项目中使用QtMqtt?

时间:2020-05-31 18:17:33

标签: qt cmake mqtt qmake

要在qmake项目文件(* .pro)中使用Qt MQTT库,应添加QT += mqtt

什么是CMake pandan?

2 个答案:

答案 0 :(得分:3)

基于the official example如何在Qt中使用cmake,我创建了CMakeLists.txt来编译官方的Qt Mqtt示例之一:Simple MQTT Client Example

cmake_minimum_required(VERSION 3.1.0)

project(simplemqttclient)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

if(CMAKE_VERSION VERSION_LESS "3.7.0")
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()

find_package(Qt5 COMPONENTS Widgets Mqtt REQUIRED)

add_executable(simplemqttclient
    mainwindow.ui
    mainwindow.cpp
    main.cpp
)

target_link_libraries(simplemqttclient Qt5::Widgets Qt5::Mqtt)

答案 1 :(得分:0)

我不是很精通CMake脚本,但是应该是:

find_package(Qt5Mqtt REQUIRED)