diff --git a/Qt_EQL/tutorial/main.cpp b/Qt_EQL/tutorial/main.cpp index 62ddd92..c41b356 100644 --- a/Qt_EQL/tutorial/main.cpp +++ b/Qt_EQL/tutorial/main.cpp @@ -23,9 +23,9 @@ int main(int argc, char* argv[]) { EQL::addObject(new Test(main), "*test*", true); // 'define-qt-wrappers' - EQL::eval("(load \"test.lisp\")"); // will start a REPL - app.processEvents(); // needed for 'qlater' in 'test.lisp' + EQL::eval("(load \"test.lisp\")"); // will start a REPL + app.processEvents(); // needed for 'qlater' in 'test.lisp' - return 0; // no 'app.exec()' because of REPL + return 0; // no 'app.exec()' because of REPL } diff --git a/Qt_EQL/tutorial/test.h b/Qt_EQL/tutorial/test.h index 773a17a..fdac7a3 100644 --- a/Qt_EQL/tutorial/test.h +++ b/Qt_EQL/tutorial/test.h @@ -19,7 +19,7 @@ public Q_SLOTS: // pointers, of course), as you'll find in any Qt example code QString concat(const QStringList&); - // pass Lisp data ('cl_object' is just a pointer) + // pass Lisp data ('cl_object' is just a word hosting e.g. a pointer) void processData(cl_object); // call back to Lisp diff --git a/src/ecl_fun.cpp b/src/ecl_fun.cpp index 41b7e37..faa109e 100644 --- a/src/ecl_fun.cpp +++ b/src/ecl_fun.cpp @@ -126,6 +126,8 @@ void iniCLFunctions() { cl_make_package(1, eql); } si_select_package(eql); DEFUN ("%error-msg", error_msg2, 2) + DEFUN ("%finalize", finalize2, 1) + DEFUN ("%finalize-and-delete", finalize_and_delete2, 1) DEFUN ("%make-qimage/dangerous", make_qimage_dangerous, 5) DEFUN ("no-qexec", no_qexec, 0) DEFUN ("qadd-event-filter", qadd_event_filter, 3) @@ -695,6 +697,9 @@ QtObject toQtObject(cl_object l_obj, cl_object l_cast, bool* qobject_align, bool static cl_object new_qt_object(void* pointer, uint unique, int id, bool finalize = false) { STATIC_SYMBOL_PKG (s_new_qt_object, "NEW-QT-OBJECT", "EQL") + QPointer* safePointer = 0; + if((id > 0) && pointer) { // QObject + safePointer = new QPointer((QObject*)pointer); } cl_object l_qt_object = cl_funcall(5, s_new_qt_object, ecl_make_unsigned_integer((quintptr)pointer), diff --git a/src/ecl_fun.h b/src/ecl_fun.h index 18fa2c6..9f16c0e 100644 --- a/src/ecl_fun.h +++ b/src/ecl_fun.h @@ -242,6 +242,8 @@ class QObject; class QEvent; cl_object error_msg2 (cl_object, cl_object); +cl_object finalize2 (cl_object); +cl_object finalize_and_delete2 (cl_object); cl_object make_qimage_dangerous (cl_object, cl_object, cl_object, cl_object, cl_object); cl_object no_qexec (); cl_object qadd_event_filter (cl_object, cl_object, cl_object); @@ -299,10 +301,11 @@ cl_object set_shutdown_p (cl_object); struct EQL_EXPORT QtObject { void* pointer; + QPointer* safe_pointer; uint unique; int id; - QtObject() : pointer(0), unique(0), id(0) {} + QtObject() : pointer(nullptr), safe_pointer(nullptr), unique(0), id(0) {} bool isQObject() const { return (id > 0); } bool isStatic() const { return !pointer; } diff --git a/src/lisp/ini.lisp b/src/lisp/ini.lisp index ddc4d55..81bc8f8 100644 --- a/src/lisp/ini.lisp +++ b/src/lisp/ini.lisp @@ -391,8 +391,7 @@ (defun new-qt-object (pointer unique id finalize) (let ((obj (qt-object pointer unique id finalize))) - (when finalize - (ext:set-finalizer obj 'qdelete)) + (ext:set-finalizer obj (if finalize '%finalize-and-delete '%finalize)) obj)) (defmethod print-object ((object qt-object) s) diff --git a/src/lisp/qml.lisp b/src/lisp/qml.lisp index 562b02a..5703894 100644 --- a/src/lisp/qml.lisp +++ b/src/lisp/qml.lisp @@ -78,7 +78,7 @@ (|rootContext| *quick-view*))) (defun find-quick-item (object-name) - "Finds the first QQuickItem matching OBJECT-NAME. Locally define *ROOT-ITEM* if you want to find items inside a specific item, like in a QML Repeater. See also note in sources." + "Finds the first QQuickItem matching OBJECT-NAME. You may set *ROOT-ITEM* if you want to find items inside a specific item, like in a QML Repeater. See also note in sources." ;; ;; when to use *ROOT-ITEM* ;; @@ -91,10 +91,14 @@ ;; inside the Repeater (note QRUN* which is needed because of the special ;; variable and threads): ;; - ;; (qrun* (let ((qml:*root-item* (q! |itemAt| ui:*repeater* 0))) - ;; ;; everything we do here will only affect children of the first - ;; ;; item in ui:*repeater* (see index 0 above) - ;; (q< |text| ui:*edit*))) + ;; (setf qml:*root-item* (q! |itemAt| ui:*repeater* 0)) ; (1) set + ;; ;; everything we do here will only affect children of the first + ;; ;; item in ui:*repeater* (see index 0 above) + ;; (q< |text| ui:*edit*) + ;; (setf qml:*root-item* nil) ; (2) reset + ;; + ;; N.B. we need SETF here because of the global variable and threads (because + ;; QRUN* is used internally here) ;; (let ((parent (or *root-item* (root-item)))) (unless (qnull parent)