t-artistik / qtscriptgenerator

Automatically exported from code.google.com/p/qtscriptgenerator
0 stars 0 forks source link

Unable to pass script values as QVariant to C++ #43

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

I have a QScriptable class that has a slot that looks like this:

void sendToDestination( uint destType, const QString &dest, uint msgType,
const QVariant &msg );

I am using QVariant as the last parameter to allow me to pass a string or
an Object from the script.

What is the expected output? What do you see instead?

I expect to get either a QVariant::String or QVariant::Map in the C++ code.
When I call it with a string, the result is as expected. However, when I
call it with an object like this:

var mapMsg = new Object;
mapMsg.k1 = "v1";
mapMsg.k2 = "v2";
mapMsg.k3 = "v3";

ems.sendToDestination( ems.TIBEMS_TOPIC, topic, ems.TIBEMS_MAP_MESSAGE,
mapMsg )

I get the value as QVariant::String in the C++ code, instead of
QVariant::Map. The value of this string is "[object Object]". Looks like
QtScript is calling the toString() method on the Object and always creating
a QVariant( QString ) instead of creating a QVariant( QVariantMap ) as I
expect it to.

What version of the product are you using? On what operating system?

Qt-4.5.0 on SLES9, built from source.

Please provide any additional information below.

Original issue reported on code.google.com by nhasan%n...@gtempaccount.com on 7 Apr 2009 at 5:14

GoogleCodeExporter commented 8 years ago
After looking deeper, it looks like the culprit is QScriptValue::toVariant(). 
It does
not support script values that are plain Objects ( var val = new Object;). It 
tries
to convert them to a primitive value by calling Object.toString(). See
QScriptEnginePrivate::toPrimitive_helper() for details.

I think this is a bit flawed. QScriptValue should detect if this is a plain 
object
and convert them to QVariantMap before trying to treat it as a primitive.

Original comment by nhasan%n...@gtempaccount.com on 7 Apr 2009 at 9:40

GoogleCodeExporter commented 8 years ago
This isn't a bug tracker for all things QtScript, but for the QtScript Qt 
bindings.

http://doc.trolltech.com/4.5/bughowto.html

Original comment by ian.mon...@gmail.com on 8 Apr 2009 at 2:06

GoogleCodeExporter commented 8 years ago
Ian,

Initially I thought this could be binding related. Upon further research, I 
realized
that this is a QtScript issue and offtopic here. I just forgot to add that line 
in my
last comment :)

Original comment by nhasan%n...@gtempaccount.com on 8 Apr 2009 at 1:18

GoogleCodeExporter commented 8 years ago
Now that I am thinking more clearly, this couldn't have been a binding related 
issue
in the first place. I am not even sure now if this is a Qt bug since it seems 
this
behavior is documented.

Sorry for the noise. I guess I had one of those confused moments.

Original comment by nhasan%n...@gtempaccount.com on 8 Apr 2009 at 1:45

GoogleCodeExporter commented 8 years ago
There is already an entry in the task tracker for this:

http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id=2432
95

Original comment by nhasan%n...@gtempaccount.com on 14 Apr 2009 at 1:21

GoogleCodeExporter commented 8 years ago
http://bugreports.qt.nokia.com/browse/QTBUG-3511

Original comment by kentm...@gmail.com on 11 Nov 2010 at 9:54