Add name + version in About view
This commit is contained in:
		
							parent
							
								
									95a1f784fc
								
							
						
					
					
						commit
						fe2c5e8ba1
					
				
					 4 changed files with 44 additions and 26 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,28 +6,15 @@
 | 
			
		|||
#include <caml/mlvalues.h>
 | 
			
		||||
#include <caml/callback.h>
 | 
			
		||||
 | 
			
		||||
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<OBoy>("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();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,31 @@
 | 
			
		|||
#include "oboy.h"
 | 
			
		||||
 | 
			
		||||
#include <caml/mlvalues.h>
 | 
			
		||||
#include <caml/callback.h>
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue