[Qt-qml] Objects get mangled into QVariantMaps when passed from QtScript to QML functions... why?
Kent Hansen
kent.hansen at nokia.com
Mon Dec 6 09:50:49 CET 2010
Hi,
Den 02. des. 2010 23:50, skrev ext Bart Kelsey:
> I've attached a small test case that demonstrates the issue. Note
> that when the Object gets passed from QtScript to QML, it makes a copy
> instead of passing a reference.
>
> Thanks for your help,
> Bart
>
>
> On Thu, Dec 2, 2010 at 1:43 PM, Bart Kelsey <elbarto at gmail.com
> <mailto:elbarto at gmail.com>> wrote:
>
> Sorry I didn't reply to this earlier... somehow I managed to miss
> it. I'll do my best to reduce this issue down to a test case and
> then contact you with it when I do.
>
> Thanks for your help!
>
> Bart
>
>
>
> On Tue, Nov 30, 2010 at 3:47 AM, Kent Hansen
> <kent.hansen at nokia.com <mailto:kent.hansen at nokia.com>> wrote:
>
> Hi,
>
> Den 29. nov. 2010 15:54, skrev ext Bart Kelsey:
> > My current project is a game engine that uses QML for the UI and
> > QtScript for game scripting (video at
> > http://www.youtube.com/watch?v=SG5p-qLARrw ). At any rate,
> while it's
> > possible to call functions on QML elements from QtScript,
> when I try
> > to pass an object to that function (even a
> QDeclarativeItem), it gets
> > mangled into a QVariantMap (as opposed to a reference to the
> actual
> > object that I passed, which is what I need). Why is this?
> Is there
> > any way I can stop it from happening and pass the object as
> a reference?
>
> Could you provide a small compileable application that
> demonstrates the
> issue?
>
> Kent
>
Please keep this thread on the mailing list.
QML has its own script engine internally. You can't pass an object
reference from one script engine (yours) to another (QML's).
In any case, what's happening here is that for the following QML
Rectangle {
function foo(arg) { }
}
the implementation will create a meta-object that contains a function
with signature
foo(QVariant)
When you pass a script object to this function, QtScript will try to
convert the argument to a variant. The default behavior is to call
QScriptValue::toVariant(), which converts the object to a QVariantMap.
Regards,
Kent
More information about the Qt-qml
mailing list