go-qml / qml

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

Fixed unsupported variant type: 1024 (QJSValue) #140

Open obscuren opened 9 years ago

obscuren commented 9 years ago

Added proper casting from QMetaType::User (1024) with userType 1034 (i.e., QJSValue) to QVariant so it can be handled properly by the packDataValue method.

pjoe commented 9 years ago

I tried this with limetext/qml .. however for me the userType is 1051 ... will try a way to not hardcode this

pjoe commented 9 years ago

Here is what i ended up with, which seems to work:

diff --git a/cpp/capi.cpp b/cpp/capi.cpp
index 55ac585..c2255aa 100644
--- a/cpp/capi.cpp
+++ b/cpp/capi.cpp
@@ -745,7 +745,8 @@ void packDataValue(QVariant_ *var, DataValue *value)
         break;
     case QMetaType::User:
         {
-            if (qvar->userType() == 1034) {
+            static const int qjstype = QVariant::fromValue(QJSValue()).userType();
+            if (qvar->userType() == qjstype) {
                 auto var = qvar->value<QJSValue>().toVariant();
                 packDataValue(&var, value);
             }
obscuren commented 9 years ago

Confirmed. @pjoe change works. Updated PR.

niemeyer commented 9 years ago

We need a test case exercising the issue to make sure we understand the problem and it doesn't not regress.

Also, can you please sign the agreement so we can get the change in:

http://www.ubuntu.com/legal/contributors

tgerring commented 9 years ago

I don't think it was c288002b52e905973b131089a8a7c761d4a2c36a was intended to be part of the original PR, but it may be obsoleted by 154c0d11e675c3ee440e05fe005428a74d9b9e17 which was merged in 2ee7e5ff737026a4dfa89801fac63561279040f4

immesys commented 8 years ago

@niemyer, please can you merge this in. It's really useful.