qtools icon indicating copy to clipboard operation
qtools copied to clipboard

q+:exec failing

Open nchodosh opened this issue 6 years ago • 5 comments

I'm using SBCL 1.3.20 (on Ubuntu 16.04) and I sporadically get the following error when using with-main-window

A simple application lsuch as following:

(define-widget notepad (QWidget)
  ())

(define-subwidget (notepad text-edit) (q+:make-qtextedit))

(define-subwidget (notepad quit-button) 
    (q+:make-qpushbutton "&Quit" notepad))

(define-subwidget (notepad layout) (q+:make-qvboxlayout notepad)
  (q+:add-widget layout text-edit)
  (q+:add-widget layout quit-button))

(define-slot (notepad quit) ()
  (declare (connected quit-button (released)))
   (q+:close notepad))

works the first time I run it. However if the application terminates with an error, or I change the definition of a slot, the next call to qt+:exec starts failing with the error: "QApplicaiton::exec: Must be called from the main thread".

nchodosh avatar Apr 25 '18 03:04 nchodosh

Are you using C-c C-c or similar to evaluate your with-main-window form? This spawns a new thread every time, which Qt cannot deal with. You must always launch it from the same thread, such as the REPL thread.

Shinmera avatar Jul 27 '18 06:07 Shinmera

No I always launch it from the REPL by evaluating a function which uses with-main-window. If the app exits normally I can re-launch it. I only have the issue after aborting the thread when an error is thrown.

nchodosh avatar Aug 08 '18 16:08 nchodosh

In that case it's possible that the unwind leaves Qt in an unfavourable state, making it unable to restart. I've observed this myself occasionally, but don't have any idea on what exactly happens or how to remedy it, aside from the advice of: don't cause errors outside of callbacks.

Shinmera avatar Aug 08 '18 16:08 Shinmera

I see, thanks!

nchodosh avatar Aug 15 '18 15:08 nchodosh

Clarification: you can cause errors outside of callbacks, but when you attempt to remedy them, you must not use the toplevel ABORT restart to recover from callbacks - this will render your Lisp image unable to use Qt, as the *inferior-lisp* buffer will say something like QApplication::exec: The event loop is already running and the Qt execution will fail.

Use some of the available Abort smoke callback restarts to recover from these errors.

phoe avatar Mar 19 '19 21:03 phoe