Add name + version in About view

This commit is contained in:
Fabien Freling 2019-05-11 21:13:09 +02:00
parent 95a1f784fc
commit fe2c5e8ba1
4 changed files with 44 additions and 26 deletions

View file

@ -1,5 +1,6 @@
import QtQuick 2.4 import QtQuick 2.4
import QtQuick.Window 2.0 import QtQuick.Window 2.0
import com.oboy.oboy 1.0
Window { Window {
title: "About" title: "About"
@ -12,8 +13,17 @@ Window {
maximumHeight: height maximumHeight: height
minimumHeight: height minimumHeight: height
OBoy {
id: oboy
}
Text { Text {
id: name id: name
text: qsTr("About name") text: oboy.name
}
Text {
id: version
text: oboy.version
anchors.top: name.bottom
} }
} }

View file

@ -6,28 +6,15 @@
#include <caml/mlvalues.h> #include <caml/mlvalues.h>
#include <caml/callback.h> #include <caml/callback.h>
void load_caml(char *argv[]) #include "oboy.h"
{
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";
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
qmlRegisterType<OBoy>("com.oboy.oboy", 1, 0, "OBoy");
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml")); const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
@ -37,12 +24,7 @@ int main(int argc, char *argv[])
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
engine.load(url); engine.load(url);
load_caml(argv); caml_main(argv);
std::cout << "test std::cout" << "\n";
std::cerr << "test std::cerr" << "\n";
print_closure("name");
print_closure("version");
return app.exec(); return app.exec();
} }

View file

@ -1,6 +1,31 @@
#include "oboy.h" #include "oboy.h"
#include <caml/mlvalues.h>
#include <caml/callback.h>
OBoy::OBoy(QObject *parent) : QObject(parent) OBoy::OBoy(QObject *parent) : QObject(parent)
{ {
} }
QString OBoy::name() const
{
value * closure_f = caml_named_value("name");
if (closure_f == nullptr) {
return QString("<Unreachable>");
}
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("<Unreachable>");
}
const char *str = String_val(caml_callback(*closure_f, Val_unit));
return QString(str);
}

View file

@ -5,10 +5,11 @@
class OBoy : public QObject class OBoy : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString name READ name)
Q_PROPERTY(QString version READ version)
public: public:
explicit OBoy(QObject *parent = nullptr); explicit OBoy(QObject *parent = nullptr);
/* signals: */ QString name() const;
QString version() const;
/* public slots: */
}; };