JuliaGraphics / QML.jl

Build Qt6 QML interfaces for Julia programs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type mismatch on Linux when sending an integer from Julia to QML

a-ill opened this issue · comments

commented

Here is a minimal reproducible example.


using QML, Qt5QuickControls2_jll

function get_int()
    return 1
end

function QML.loadqml(text::QByteArray; kwargs...)
    qml_engine = init_qmlengine()
    ctx = root_context(QML.CxxRef(qml_engine))
    for (key,value) in kwargs
        set_context_property(ctx, String(key), value)
    end
    component = QQmlComponent(qml_engine)
    QML.set_data(component, text, QUrl())
    create(component, qmlcontext())
    return component
end

text = QByteArray("""
    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import org.julialang 1.0

    ApplicationWindow {
        visible: true
        Timer {
            running: true
            onTriggered: {
                var int_val = Julia.get_int()
                console.log(typeof int_val, int_val)
                Qt.quit()
            }
        }
    }
""")

@qmlfunction(get_int,send_int)
loadqml(text)
exec()

On Windows we get

Qt Debug: number 1 (:11, onTriggered)

On Linux we get

Qt Debug: object 1 (:11, onTriggered)

After using such a number with object type it sometimes becomes an empty object {} resulting in an error. Floats and strings do not have such an issue.

Integers in QML are 32bit. Did you try sending 32 bit integers?