JuliaGraphics / QML.jl

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

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

Open a-ill opened 3 years ago

a-ill commented 3 years ago

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.

ufechner7 commented 1 year ago

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