Permalink
Browse files

Helloworld app added

  • Loading branch information...
Kakadu committed Dec 15, 2013
1 parent 3313279 commit 6ebe55a87e1c8738a6cd876ac45c0cdcb0f1882a
@@ -0,0 +1,4 @@
+*.cm[oxi]
+*.o
+camlcode.o.startup.s
+helloworld1
View
@@ -0,0 +1,5 @@
+For compilation you need correct Qt5 environment with LABLQT variable set.
+
+In this example you can find QML GUI with onclick handler in JavaScript.
+OCaml startup code is added too.
+
View
@@ -0,0 +1,16 @@
+import QtQuick 2.0
+import QtQuick.Controls 1.0
+
+ApplicationWindow {
+ color: "#FFFFDF" // we declare rectangle with custom background color
+ width: 400;
+ height: 300; // with custom size
+ Text {
+ anchors.centerIn: parent
+ text: "Click me!"
+ }
+ MouseArea {
+ anchors.fill: parent // all space in parent Rectangle will be clickable
+ onClicked: controller.onMouseClicked("message")
+ }
+}
View
Binary file not shown.
View
@@ -0,0 +1,12 @@
+[
+{
+ "classname": "Controller",
+ "methods":
+ [ { "name": "onMouseClicked",
+ "signature": ["string", "unit"] }
+ ],
+ "properties": [],
+ "slots": [],
+ "signals": []
+}
+]
View
@@ -0,0 +1,30 @@
+#include "stubs.h"
+
+#include <QtGui/QGuiApplication>
+#include <QtQuick/qquickview.h>
+
+void doCaml() {
+ CAMLparam0();
+ static value *closure = nullptr;
+ if (closure == nullptr) {
+ closure = caml_named_value("doCamlInitialization");
+ }
+ Q_ASSERT(closure!=nullptr);
+ caml_callback(*closure, Val_unit); // should be a unit
+ CAMLreturn0;
+}
+
+int main(int argc, char ** argv) {
+ caml_main(argv);
+ QGuiApplication app(argc, argv);
+ QQuickView view;
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+
+ QQmlContext *ctxt = view.rootContext();
+ registerContext(QString("rootContext"), ctxt);
+ doCaml();
+ view.setSource(QUrl::fromLocalFile(QString("Root.qml")));
+ view.show();
+
+ return app.exec();
+}
View
@@ -0,0 +1,14 @@
+open QmlContext
+
+let main () =
+ let controller_cppobj = Controller.create_Controller () in
+ let controller = object(self)
+ inherit Controller.base_Controller controller_cppobj as super
+ method onMouseClicked msg = Printf.printf "OCaml says: '%s'\n%!" msg
+ end in
+ set_context_property ~ctx:(get_view_exn ~name:"rootContext") ~name:"controller" controller#handler;
+ print_endline "startup initialiation at OCaml side"
+
+let () =
+ run_with_QQmlApplicationEngine Sys.argv main "Root.qml"
+

0 comments on commit 6ebe55a

Please sign in to comment.