From 2ff97c588c5fb26bd1da9f0f8fcbdfe8eea3e4e5 Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Tue, 3 Mar 2026 18:58:34 +0100 Subject: [PATCH] Accessing the core and the model from this QML UI project. --- CMakeLists.txt | 3 +++ Main.qml | 5 +++++ main.cpp | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a60212..d34032e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,9 @@ set_target_properties(${TARGET_APP} PROPERTIES WIN32_EXECUTABLE TRUE ) +target_include_directories(${TARGET_APP} PRIVATE ${CORE_LIB_DIR}/) +target_link_libraries(${TARGET_APP} PRIVATE GenericCore) + target_link_libraries(${TARGET_APP} PRIVATE Qt6::Quick ) diff --git a/Main.qml b/Main.qml index 41424f8..1cb8933 100644 --- a/Main.qml +++ b/Main.qml @@ -5,4 +5,9 @@ Window { height: 480 visible: true title: qsTr("Hello World") + + Text { + text: "Model row count: " + mainModel.rowCount() + anchors.centerIn: parent + } } diff --git a/main.cpp b/main.cpp index c26fc57..5ed00ff 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,31 @@ #include #include +#include + +#include + +#include "genericcore.h" + +#ifdef QT_DEBUG +#include "utils/messagehandler.h" +#endif int main(int argc, char* argv[]) { +#ifdef QT_DEBUG + qInstallMessageHandler(consoleHandlerColoredVerboseInDarkTheme); +#endif + QGuiApplication app(argc, argv); + std::unique_ptr core = std::make_unique(); + std::shared_ptr mainModel = core->getSortFilterModel(); + + // qInfo() << "QMLApp Version:" << QMLAPP_VERSION; + qInfo() << "core->getString():" << core->toString(); QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty(QStringLiteral("core"), core.get()); + engine.rootContext()->setContextProperty(QStringLiteral("mainModel"), mainModel.get()); + QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);