go-qml / qml

QML support for the Go language
Other
1.96k stars 189 forks source link

Qt 5.4 panic: unsupported variant type: 1024 (QJSValue) #137

Open obscuren opened 9 years ago

obscuren commented 9 years ago

Using QT 5.4.0 with qml v1 and exporting the following object:

type MyObject struct {}
func (m *MyObject) Call(m map[string]interface{}) {
    fmt.Println(m)
}
context.SetVar("m", &MyObject{})
// m.call( {} );

Will result in: panic: unsupported variant type: 1024 (QJSValue)

Possible solution On https://github.com/go-qml/qml/blob/v1/cpp/capi.cpp#L725 add a case QMetaType::User:

obscuren commented 9 years ago

After doing some testing the above possible solution didn't turn out to work properly.

I've updated it with the following (and will send a proper PR once fully tested)

case QMetaType::User:
    {
        if (qvar->userType() == 1034)
        {
            auto var = qvar->value<QJSValue>().toVariant();
            packDataValue(&var, value);
        }
        else
        {
            qDebug() << "user-type =" << qvar->userType() << " name =" << QVariant::typeToName(qvar->userType());
        }
    }
    break;

I've left the qDebug in for debugging purposes (hasn't occurred yet after some testing). I also couldn't find a proper constant for 1034 (i.e. QJSValue).

obscuren commented 9 years ago

Created PR, see https://github.com/go-qml/qml/pull/140

janimo commented 8 years ago

I see this error when trying to pass a Javascript array to a function on an object exported from Go.

janimo commented 8 years ago

The diff from the PR fixes it for me.

bcampbell commented 8 years ago

Just to add, I've been seeing the same error, when passing a javascript array out from QML to a go function on Qt 5.4.2. But I don't know where it crept in exactly, as I did a go get -u on go-qml and upgraded from Qt5.2 at the same time...

Anyway, PR #140 also fixed it for me.