From a4f496d259796c277cf5abcd0d53c7fa10972d01 Mon Sep 17 00:00:00 2001 From: Bas Schouten Date: Tue, 31 Jan 2023 20:21:52 +0100 Subject: [PATCH] Downgrade to Qt5 for Pi0 compatibility. --- CMakeLists.txt | 62 +++++++++++++++++++++++++++++++++++-------------- main.cpp | 8 ++++++- main.qml | 23 +++--------------- mqttinterface.h | 2 +- qml.qrc | 5 ++++ 5 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 qml.qrc diff --git a/CMakeLists.txt b/CMakeLists.txt index ff02d94..6f09178 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,30 +1,54 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.14) -project(qthomecontrol VERSION 0.1 LANGUAGES CXX) +project(test VERSION 0.1 LANGUAGES CXX) +set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_AUTORCC ON) -find_package(Qt6 6.2 COMPONENTS Quick REQUIRED) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) if (UNIX) add_subdirectory ("paho.mqtt.c") endif(UNIX) -qt_add_executable(appqthomecontrol - main.cpp - mqttinterface.cpp - mqttinterface.h -) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick) -qt_add_qml_module(appqthomecontrol - URI qthomecontrol - VERSION 1.0 - QML_FILES main.qml - SOURCES - mqttinterface.h mqttinterface.cpp +set(PROJECT_SOURCES + main.cpp + qml.qrc + mqttinterface.cpp + mqttinterface.h ) +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(appqthomecontrol + MANUAL_FINALIZATION + ${PROJECT_SOURCES} + ) +# Define target properties for Android with Qt 6 as: +# set_property(TARGET test APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR +# ${CMAKE_CURRENT_SOURCE_DIR}/android) +# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation +else() + if(ANDROID) + add_library(appqthomecontrol SHARED + ${PROJECT_SOURCES} + ) +# Define properties for Android with Qt 5 after find_package() calls as: +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") + else() + add_executable(appqthomecontrol + ${PROJECT_SOURCES} + ) + endif() +endif() + +target_link_libraries(appqthomecontrol + PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick) + set_target_properties(appqthomecontrol PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} @@ -35,9 +59,6 @@ set_target_properties(appqthomecontrol PROPERTIES target_include_directories (appqthomecontrol PRIVATE paho.mqtt.c/src) -target_link_libraries(appqthomecontrol - PRIVATE Qt6::Quick) - if (WIN32) target_link_libraries (appqthomecontrol PRIVATE ${CMAKE_SOURCE_DIR}/paho.mqtt.c/src/Release/paho-mqtt3a.lib ${CMAKE_SOURCE_DIR}/paho.mqtt.c/src/Release/paho-mqtt3c.lib) endif (WIN32) @@ -48,3 +69,8 @@ endif(UNIX) install(TARGETS appqthomecontrol BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +if(QT_VERSION_MAJOR EQUAL 6) + qt_import_qml_plugins(qthomecontrol) + qt_finalize_executable(qthomecontrol) +endif() diff --git a/main.cpp b/main.cpp index e4ddce2..2124962 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,19 @@ #include #include +#include "mqttinterface.h" int main(int argc, char *argv[]) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif QGuiApplication app(argc, argv); + qmlRegisterType("QtHomeControl", 1, 0, "MQTTInterface"); + QQmlApplicationEngine engine; - const QUrl url(u"qrc:/qthomecontrol/main.qml"_qs); + const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) diff --git a/main.qml b/main.qml index b5b938d..b761750 100644 --- a/main.qml +++ b/main.qml @@ -1,7 +1,6 @@ -import QtQuick -import QtQuick.Controls 6.3 -import QtQuick.Layouts 6.3 -import qthomecontrol +import QtQuick 2.15 +import QtQuick.Window 2.15 +import QtHomeControl 1.0 Window { width: 720 @@ -14,22 +13,6 @@ Window { id: mqttinterface } - Slider { - id: slider - x: 13 - y: 534 - width: 695 - height: 178 - live: true - antialiasing: false - topPadding: 0 - orientation: Qt.Horizontal - snapMode: RangeSlider.SnapOnRelease - stepSize: 1 - to: 100 - value: 0 - } - Text { id: text1 x: 206 diff --git a/mqttinterface.h b/mqttinterface.h index 1b54a9a..e2e4340 100644 --- a/mqttinterface.h +++ b/mqttinterface.h @@ -2,7 +2,7 @@ #define MQTTINTERFACE_H #include -#include +#include #include #include "MQTTClient.h" diff --git a/qml.qrc b/qml.qrc new file mode 100644 index 0000000..5f6483a --- /dev/null +++ b/qml.qrc @@ -0,0 +1,5 @@ + + + main.qml + + -- 2.47.3