My real code runs great, but for some reason gives a segfault when exiting the Julia REPL. Then I saw JuliaPropertyMaps
should be a function in the docs .
I modified the doc example to show my problem (I need “Hi” to become “Hello”):
using QML
# Propertymap is a pointer, so it needs to be a function and not a const value
props() = JuliaPropertyMap(
"hi" => "Hi",
)
world() = " world!"
# Convenience function to call all relevant function macros
function define_funcs()
@qmlfunction world
end
function main(qml_file)
define_funcs()
loadqml(qml_file; props=props())
exec()
end
mktempdir() do folder
path = joinpath(folder, "frommodule.qml")
write(path, """
import QtQuick
import QtQuick.Controls
import org.julialang
ApplicationWindow {
id: mainWin
title: "My Application"
width: 400
height: 400
visible: true
Rectangle {
anchors.fill: parent
color: "red"
Button {
anchors.centerIn: parent
text: props.hi + Julia.world()
onClicked: { props.hi = "Hello"; console.log("Value:", props.hi) }
}
}
}
""")
main(path)
end
props()
Results:
Qt Debug: Value: Hello (file:///tmp/jl_Lq0Tc5/frommodule.qml:19, expression for onClicked)
julia> props()
JuliaPropertyMap with 1 entry:
"hi" => "Hi"
If I use this method to avoid the segfault (not sure yet if that will work for this case), how can I pass the new value to Julia?
Bonus
Here is the error I am trying to avoid on exiting Julia:
[2093301] signal 11 (1): Segmentation fault
in expression starting at none:0
unknown function (ip: 0x20)
_ZN5jlcxx6detail11CallFunctorIvJPN7qmlwrap14JuliaItemModelEEE5applyEPKvNS_13WrappedCppPtrE at /home/user/.julia/artifacts/7bc654121da55f7ea29f116c66155e8e5ebb43ff/lib/libjlqml.so (unknown line)
Allocations: 42114717 (Pool: 42113248; Big: 1469); GC: 25
Segmentation fault (core dumped)
The relevant code to the segfault looks like the below. Not a MWE unfortunately.
Julia:
mutable struct Ivals
name :: String
idx :: Int
sel :: Bool
end
function update_params(dat)
params["ivals"] = new_ivals
end
@qmlfunction load_data
@qmlfunction update_params
ivals = JuliaItemModel(Ivals.(names(dat)[ivals0], ivals0, false))
params = JuliaPropertyMap("ivals" = ivals)
loadqml(qmlfile, params = params)
QML:
params.dat = Julia.load_data(params.fpath)
Julia.update_params(params.dat)
Additional info
Say instead I try to assign the new values from the QML (which works for other values that are not JuliaItemModel
):
Julia:
function update_params(dat)
return new_ivals
end
QML:
params.ivals = Julia.update_params(params.dat)
Before ivals
is updated:
println(ivals)
QML.JuliaItemModelAllocated(Ptr{Nothing} @0x00000000035fee70)
println(propertynames(ivals))
(:cpp_object,)
After update:
println(ivals)
QML.QObjectDereferenced(Ptr{Nothing} @0x00000000058be580)
println(propertynames(ivals))
(:cpp_object,)
Then I start seeing a different error to track down:
MethodError: no method matching length(::QML.QObjectDereferenced)
Maybe that is the easiest fix? Any ideas?