diff --git a/src/qt/About.qml b/src/qt/About.qml index d1e4c8a..3f9a5f8 100644 --- a/src/qt/About.qml +++ b/src/qt/About.qml @@ -1,5 +1,6 @@ import QtQuick 2.4 import QtQuick.Window 2.0 +import com.oboy.oboy 1.0 Window { title: "About" @@ -12,8 +13,17 @@ Window { maximumHeight: height minimumHeight: height + OBoy { + id: oboy + } + Text { id: name - text: qsTr("About name") + text: oboy.name + } + Text { + id: version + text: oboy.version + anchors.top: name.bottom } } diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 0c060ec..77c39f5 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -6,28 +6,15 @@ #include #include -void load_caml(char *argv[]) -{ - caml_main(argv); -} - -void print_closure(const std::string &closure_name) { - value * closure_f = caml_named_value(closure_name.c_str()); - if (closure_f == nullptr) { - std::cerr << "ERROR: Unreachable closure " << closure_name << "\n"; - return; - } - - const char *str = String_val(caml_callback(*closure_f, Val_unit)); - std::cout << closure_name << ": " << str << "\n"; -} - +#include "oboy.h" int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); + qmlRegisterType("com.oboy.oboy", 1, 0, "OBoy"); + QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, @@ -37,12 +24,7 @@ int main(int argc, char *argv[]) }, Qt::QueuedConnection); engine.load(url); - load_caml(argv); - - std::cout << "test std::cout" << "\n"; - std::cerr << "test std::cerr" << "\n"; - print_closure("name"); - print_closure("version"); + caml_main(argv); return app.exec(); } diff --git a/src/qt/oboy.cpp b/src/qt/oboy.cpp index 216a464..4a0d509 100644 --- a/src/qt/oboy.cpp +++ b/src/qt/oboy.cpp @@ -1,6 +1,31 @@ #include "oboy.h" +#include +#include + OBoy::OBoy(QObject *parent) : QObject(parent) { } + +QString OBoy::name() const +{ + value * closure_f = caml_named_value("name"); + if (closure_f == nullptr) { + return QString(""); + } + + const char *str = String_val(caml_callback(*closure_f, Val_unit)); + return QString(str); +} + +QString OBoy::version() const +{ + value * closure_f = caml_named_value("version"); + if (closure_f == nullptr) { + return QString(""); + } + + const char *str = String_val(caml_callback(*closure_f, Val_unit)); + return QString(str); +} diff --git a/src/qt/oboy.h b/src/qt/oboy.h index 6629355..804b71b 100644 --- a/src/qt/oboy.h +++ b/src/qt/oboy.h @@ -5,10 +5,11 @@ class OBoy : public QObject { Q_OBJECT + Q_PROPERTY(QString name READ name) + Q_PROPERTY(QString version READ version) public: explicit OBoy(QObject *parent = nullptr); -/* signals: */ - -/* public slots: */ + QString name() const; + QString version() const; };