Accessing the core and the model from this QML UI project.
This commit is contained in:
@ -30,6 +30,9 @@ set_target_properties(${TARGET_APP} PROPERTIES
|
|||||||
WIN32_EXECUTABLE TRUE
|
WIN32_EXECUTABLE TRUE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_include_directories(${TARGET_APP} PRIVATE ${CORE_LIB_DIR}/)
|
||||||
|
target_link_libraries(${TARGET_APP} PRIVATE GenericCore)
|
||||||
|
|
||||||
target_link_libraries(${TARGET_APP}
|
target_link_libraries(${TARGET_APP}
|
||||||
PRIVATE Qt6::Quick
|
PRIVATE Qt6::Quick
|
||||||
)
|
)
|
||||||
|
|||||||
5
Main.qml
5
Main.qml
@ -5,4 +5,9 @@ Window {
|
|||||||
height: 480
|
height: 480
|
||||||
visible: true
|
visible: true
|
||||||
title: qsTr("Hello World")
|
title: qsTr("Hello World")
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: "Model row count: " + mainModel.rowCount()
|
||||||
|
anchors.centerIn: parent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
main.cpp
21
main.cpp
@ -1,10 +1,31 @@
|
|||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
|
#include <model/generalsortfiltermodel.h>
|
||||||
|
|
||||||
|
#include "genericcore.h"
|
||||||
|
|
||||||
|
#ifdef QT_DEBUG
|
||||||
|
#include "utils/messagehandler.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
#ifdef QT_DEBUG
|
||||||
|
qInstallMessageHandler(consoleHandlerColoredVerboseInDarkTheme);
|
||||||
|
#endif
|
||||||
|
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
std::unique_ptr<GenericCore> core = std::make_unique<GenericCore>();
|
||||||
|
std::shared_ptr<GeneralSortFilterModel> mainModel = core->getSortFilterModel();
|
||||||
|
|
||||||
|
// qInfo() << "QMLApp Version:" << QMLAPP_VERSION;
|
||||||
|
qInfo() << "core->getString():" << core->toString();
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
|
engine.rootContext()->setContextProperty(QStringLiteral("core"), core.get());
|
||||||
|
engine.rootContext()->setContextProperty(QStringLiteral("mainModel"), mainModel.get());
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
|
&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
|
||||||
[]() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);
|
[]() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);
|
||||||
|
|||||||
Reference in New Issue
Block a user