JuliaGraphics / QML.jl

Build Qt6 QML interfaces for Julia programs.
Other
381 stars 35 forks source link

Please provide forced (synchronous) redraw from Julia #32

Closed RalphAS closed 1 year ago

RalphAS commented 7 years ago

I am building an application which triggers a Julia function that runs for several minutes and provides status updates as it goes. I want to show those updates in the GUI, but I have not found a way to get the Qt window redrawn before the Julia function returns. The objects I am aiming to update are Text objects and JuliaDisplay panels. All I see now is the final version of these. (I have tried interposing sleep() and readline() calls in Julia to yield to anything scheduled, and to calling the show() method of the ApplicationWindow from a signal, all to no avail.) For now, I would be content with some way to call into Qt to force a redraw with up-to-date object states. I am using Qt 5.7.1 on Linux, Julia 0.5 and QML 0.2.0.

barche commented 7 years ago

I have added an example for this in example/progressbar.jl (QML in example/qml/progressbar.qml)

The key is to use the QTimer and call a function every time it fires. On the Julia side, you can then use a task to run a simulation step when the timer fires. As long as this step runs, the GUI is blocked and between each step the GUI is updated, including processing of input events.

The example should also work on QML.jl 0.2.0, if you prefer not to Pkg.checkout. If you do Pkg.checkout, you need to do that for CxxWrap too and run Pkg.build("QML").

RalphAS commented 7 years ago

Thanks, this is a reasonable workaround. I got a toy case more like my project to work with tasks and a timer, following your example. (It will take some time to fit the pattern into my real project.) I did observe that with the default timer only about half of the window redraws were actually done (both for my toy case and yours). I found that setting timer.interval = 10 before starting the timer gets every update to redraw in the simple cases.

barche commented 7 years ago

Yes, I had noticed that when taking smaller steps it also jumps quickly to about 20% and then moves slowly. Ideally this should be done using threads of course, but the obstacles there are that all Julia code must run in the main thread for now, and for OS X the GUI too has too run in the main thread. The QTimer solution is also officially recommended in the Qt docs, however.

JeffreySarnoff commented 7 years ago

I tried this example on Linux with both v0.5 and nightly. When I press the start button, this happens:

LLVM ERROR: Inline asm not supported by this streamer because we don't have an asm parser for this target

barche commented 7 years ago

Are you using a Gallium-3D based graphics driver by any chance? If so, setting the environment variable:

export GALLIUM_DRIVER="softpipe"

before running Julia should fix it.

ufechner7 commented 1 year ago

Closing this, because example how to do this is provided now.