Skip to content

Commit

Permalink
Fix for exec_async
Browse files Browse the repository at this point in the history
Issue `exec_async` crashes #174
  • Loading branch information
barche committed Oct 14, 2023
1 parent 5614e6a commit e4dec4e
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/QML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,19 @@ JuliaPropertyMap(dict::Dict{<:AbstractString,<:Any}) = JuliaPropertyMap(dict...)

@cxxdereference value(::Type{JuliaPropertyMap}, qvar::QVariant) = getpropertymap(qvar)

const _queued_properties = []

# Functor to update a QML property when an Observable is changed in Julia
struct QmlPropertyUpdater
propertymap::QQmlPropertyMap
key::String
active::Bool
end
function (updater::QmlPropertyUpdater)(x)
if Base.current_task() != Base.roottask
push!(_queued_properties, (updater, x))
return
end
updater.propertymap[updater.key] = x
end

Expand Down Expand Up @@ -594,19 +600,20 @@ include("itemmodel.jl")

global _async_timer

# Stop the async loop (called on quit from C++)
function _stoptimer()
if !isdefined(QML, :_async_timer)
return
end
global _async_timer
if isopen(_async_timer)
close(_async_timer)
end
end

function exec_async()
global _async_timer = Timer((t) -> process_events(), 0.015; interval=0.015)
newrepl = @async Base.run_main_repl(true,true,true,true,true)
while !istaskdone(newrepl)
for (updater, x) in _queued_properties
updater.propertymap[updater.key] = x
end
empty!(_queued_properties)
process_events()
sleep(0.015)
end
QML.quit(QML.get_qmlengine())
QML.quit()
QML.cleanup()
QML.process_events()
return
end

Expand Down

0 comments on commit e4dec4e

Please sign in to comment.