QML.jl icon indicating copy to clipboard operation
QML.jl copied to clipboard

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

Open a-ill opened this issue 4 years ago • 1 comments

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.

a-ill avatar Jul 29 '21 20:07 a-ill

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

ufechner7 avatar Sep 29 '23 02:09 ufechner7