EQL5/Qt_EQL/tutorial/test.lisp

45 lines
1.4 KiB
Common Lisp

(in-package :eql-user)
;; find main widget of app
(defvar *main-widget* (first (|topLevelWidgets.QApplication|)))
;; find 'Test' instance by its 'objectName'
(defvar *test* (qfind-child *main-widget* "test"))
;; the following defines generic functions for all Qt signals,
;; Qt slots and functions declared Q_INVOKABLE
(define-qt-wrappers *test*)
;; now we can call those functions
(defun test ()
;; make new instance
(format t "~%Creating instance of 'Test': ~A~%"
(new-instance *test* *main-widget* "test-1"))
;; call Qt slot
(format t "~%Calling 'Test::concat()': ~S~%"
(concat *test* (list "one" "two" "three")))
;; pass Lisp data
(format t "~%Processing complex Lisp data in C++:")
(process-data *test* (list 1 "virus" #\Esc 'the #(l a b)))
;; call C++ which will call back to Lisp
(print-me *test*)
(terpri))
(defun print-qt-object (object)
(format t "~%This is an instance of 'Test': ~S~%" object))
(defun repl ()
;; for playing around interactively (taken from '~/eql5/src/eql.cpp')
(setf *qtpl* t
*break-on-errors* t)
(when (directory (in-home "lib/ecl-readline.fas*"))
(load (x:check-recompile (in-home "lib/ecl-readline"))))
(qsingle-shot 500 'eql::start-read-thread)
(eql::exec-with-simple-restart)) ; start event loop
(progn
(test)
(qlater 'repl)) ; QLATER: don't block call from 'main.cpp'