1

To use Qt MQTT library in qmake project file (*.pro) QT += mqtt should be added.

What is CMake pandan for that?

dzuda11
  • 147
  • 11
  • Have you seen how QT components are incorporated in this [question](https://stackoverflow.com/q/43763416/3987854)? – Kevin May 31 '20 at 18:24
  • @squareskittles thanks for commenting on this question. I have tried it. The network module is successfully added bt the Mqtt module fails. – dzuda11 May 31 '20 at 18:28

2 Answers2

3

Based on the official example of how to use cmake with Qt I have created the CMakeLists.txt to compile one of the official Qt Mqtt examples: 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)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Heyy, I am back. Here is the cmake output https://pastebin.com/raw/MLH86ga1. Do you have any idea? – dzuda11 Jun 04 '20 at 21:33
  • @dzuda11 The error indicates that you do not have the cmake to use qtmqtt, 1) What is your OS ?, 2) How have you installed Qt? , 3) How have you installed qtmqtt? – eyllanesc Jun 04 '20 at 21:35
  • Thank you for your quick response. 1) Ubuntu 2) Yes, a have Qt and qmqtt works with qmake 3) Get source form qt git repo and then build with qmake – dzuda11 Jun 04 '20 at 21:46
  • I found Qt5MqttConfig.cmake and it is in `/home/dzuda11/developing/qtmqtt/build/lib/cmake/Qt5Mqtt/Qt5MqttConfig.cmake` - where is qmqtt source code and also in `/opt/qt/5.13.0/gcc_64/lib/cmake/Qt5Mqtt/Qt5MqttConfig.cmake` where is qt instalation – dzuda11 Jun 04 '20 at 21:49
  • I already saw the problem, by default cmake you are using the system Qt (the one you maybe installed with apt-get or was installed by default in Qt). Wait, in a few moments I will tell you how to specify the Qt – eyllanesc Jun 04 '20 at 21:51
  • Thank you very much!! – dzuda11 Jun 04 '20 at 21:52
  • @dzuda11 add `set (CMAKE_PREFIX_PATH "/opt/qt/5.13.0/gcc_64")` – eyllanesc Jun 04 '20 at 21:53
  • @dzuda11 Have you placed it at the start of the CMakeLists.txt? – eyllanesc Jun 04 '20 at 21:59
  • Yes, I have. Again it look in /usr/lib/x86_64-linux-gnu/cmake/Qt5/... – dzuda11 Jun 04 '20 at 22:00
  • @dzuda11 I will test that later, from what I understand is that you have used the offline installer, then you have downloaded and compiled using the github source code, am I correct? – eyllanesc Jun 04 '20 at 22:03
  • From `git://code.qt.io/qt/qtmqtt.git` Here is my build steps: https://pastebin.com/raw/GFAzM2d6 – dzuda11 Jun 04 '20 at 22:06
  • @dzuda11 Have you used the qmake for "/opt"? What is the output of executing "qmake -v"? – eyllanesc Jun 04 '20 at 22:08
  • Yes, I used /opt/qt/5.13.0/gcc_64/bin/qmake – dzuda11 Jun 04 '20 at 22:10
  • try add `set(Qt5_DIR "/opt/qt/5.13.0/gcc_64/lib/cmake/Qt5")` – eyllanesc Jun 04 '20 at 22:18
  • Nice, the error message has changed. https://pastebin.com/raw/c0R5Rtwa – dzuda11 Jun 04 '20 at 22:22
  • I will try to update Qt to version 5.15 and I hope that will solve the problem. – dzuda11 Jun 04 '20 at 22:25
  • @dzuda11 Okay, so you installed the wrong version of qtmqtt, clone qtmqtt using the appropriate branch for your version of Qt: `git clone -b 5.13 git://code.qt.io/qt/qtmqtt.git` – eyllanesc Jun 04 '20 at 22:26
  • YES!!! `git clone -b 5.13.0 git://code.qt.io/qt/qtmqtt.git` is right branch. THANK YOU VERY MUCH!!!!! – dzuda11 Jun 04 '20 at 22:39
0

I am not very proficient in CMake scripts, but it should be:

find_package(Qt5Mqtt REQUIRED)
bckmnn
  • 64
  • 4