[Qt-qml] Passing a QObject from QtScript to QML?

13 views
Skip to first unread message

Bart Kelsey

unread,
Jan 21, 2012, 3:06:13 PM1/21/12
to qt-...@trolltech.com
Greets!

I realize what I'm doing isn't officially supported, but I was wondering if someone could help me out.  I'm using QDeclarativeDebugHelper to pull the QScriptEngine from a QDeclarativeEngine so that I can modify the root object and run scripts directly.

Unfortunately, when I try to pass an object created in QtScript to a method in a QML component, the object gets mangled into a QVariantMap, so I'm no longer passing a reference.  This impedes my ability to pass callbacks, etc.  Is there any way I can avoid this without having to write my own little fork of Qt?  It looks like QtScript has some default conversion functions that can be overridden, but it doesn't appear that QtQuick has anything similar, and I believe the issue is occurring when the object is being passed from C++ to QML (as opposed to from QtScript -> C++).

Before anyone asks, the reason I'm doing this is that I'm using QML to build the UI for a game engine project that I'm working on.  I had originally implemented the game's scripting with QtScript and settled on a procedural design (as opposed to an OO one) for the scripts.  QML was far easier to work with to build a game UI because I don't have to mess around with a bunch of C++, but its integration with QtScript is essentially nonexistent.  My project is here:

http://gitorious.org/orange-engine

Any help would be appreciated. :)

Thanks,
Bart
--
--

Artur Souza (MoRpHeUz)

unread,
Jan 23, 2012, 7:07:54 AM1/23/12
to Bart Kelsey, qt-...@trolltech.com
Hi,

On Sat, Jan 21, 2012 at 5:06 PM, Bart Kelsey <elb...@gmail.com> wrote:
> I realize what I'm doing isn't officially supported, but I was wondering if
> someone could help me out.  I'm using QDeclarativeDebugHelper to pull the
> QScriptEngine from a QDeclarativeEngine so that I can modify the root object
> and run scripts directly.

You don't need to use the QDeclarativeDebugHelper. Take a look at this
presentation to see another way of achieving the same result (and
also, the possible drawbacks).

http://sf2011.meego.com/program/sessions/beyond-qml-use-your-js-bindings

Cheers,

--
-------------------------------------------------------
Artur Duque de Souza
openBossa
INdT - Instituto Nokia de Tecnologia
-------------------------------------------------------
Blog: http://blog.morpheuz.cc
PGP: 0xDBEEAAC3 @ wwwkeys.pgp.net
-------------------------------------------------------
_______________________________________________
Qt-qml mailing list
Qt-...@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Reply all
Reply to author
Forward
0 new messages