Improved example

This commit is contained in:
Daniel Ziltener 2022-02-05 13:38:15 +01:00
parent 412c528a27
commit c286c10fd1
3 changed files with 30 additions and 4 deletions

View File

@ -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"

View File

@ -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))

View File

@ -416,7 +416,8 @@
(dos_qobject_disconnect_with_connection_static (slot-value qmoc 'ptr)))
(define-method (delete-pointer (qmoc <QMetaObjectConnection>))
;; 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)))