From c286c10fd1a64aea63beaf3e4b339c4d92a515bf Mon Sep 17 00:00:00 2001 From: Daniel Ziltener Date: Sat, 5 Feb 2022 13:38:15 +0100 Subject: [PATCH] Improved example --- examples/helloworld.qml | 14 ++++++++++++-- examples/helloworld.scm | 17 ++++++++++++++++- qml.core.scm | 3 ++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/examples/helloworld.qml b/examples/helloworld.qml index 7c05791..c56b0ab 100644 --- a/examples/helloworld.qml +++ b/examples/helloworld.qml @@ -5,10 +5,16 @@ import QtQuick.Controls 2.15 Window { id: window + objectName: "window" visible: true width: 800 height: 600 - RowLayout { + signal close + onVisibilityChanged: { + if(visibility == Window.Hidden) + close() + } + ColumnLayout { id: rowlayout anchors.fill: parent spacing: 30 @@ -19,16 +25,20 @@ Window { color: "lightgray" Text { id: helloText + objectName: "helloText" text: "Hello World!" y: 30 anchors.horizontalCenter: parent.horizontalCenter font.pointSize: 24; font.bold: true } } - ColumnLayout { + RowLayout { spacing: 15 Layout.fillWidth: true Layout.fillHeight: true + Text { + text: qsTr("Change the text above:") + } TextField { id: nameInputField objectName: "nameInputField" diff --git a/examples/helloworld.scm b/examples/helloworld.scm index 4fd6b3e..9a14cda 100644 --- a/examples/helloworld.scm +++ b/examples/helloworld.scm @@ -1,4 +1,6 @@ (import + (chicken base) + srfi-18 (qml core) coops) @@ -21,15 +23,28 @@ (load-url engine loc) (define nameInputField (find-child (root engine) "nameInputField")) +(define helloText (find-child (root engine) "helloText")) +;; TODO: Why does the following not work? +(define window (find-child (root engine) "window")) (define (textChangeCallback cbdata argv) void - (print "Text changed to " (to (property nameInputField "text") string:))) + (print "Text changed to " (to (property nameInputField "text") string:)) + (set-property helloText "text" (property nameInputField "text"))) + +(define (closeProgram cbdata argv) void + (print "Window closed, exiting program.") + (exit 0)) (define conn2 (connect nameInputField "textEdited()" textChangeCallback textchange-cbdata (qt-connection-type auto:))) +(define conn3 (connect (root engine) "close()" + closeProgram #f + (qt-connection-type auto:))) + (do ((loop #t)) ((not loop) #t) + (thread-sleep! (seconds->time (+ 0.05 (time->seconds (current-time))))) (process-events-timed (qevent-loop-process-event-flag process-all-events:) 50)) diff --git a/qml.core.scm b/qml.core.scm index 34c995e..45266ea 100644 --- a/qml.core.scm +++ b/qml.core.scm @@ -416,7 +416,8 @@ (dos_qobject_disconnect_with_connection_static (slot-value qmoc 'ptr))) (define-method (delete-pointer (qmoc )) - ;; TODO: try-catch disconnect + (handle-exceptions exn #t + (disconnect qmoc)) (object-release (pointer->object (alist-ref intern-data-pointer: (hash-table-ref lambda-static-callbacks (callback-key qmoc))))) (hash-table-delete! lambda-static-callbacks (callback-key qmoc)) (dos_qmetaobject_connection_delete (slot-value qmoc 'ptr)))