[Qt-qml] Qml to C++
Christian Kamm
christian.d.kamm at nokia.com
Mon Jun 14 08:59:32 CEST 2010
On Friday 11 June 2010 23:57:18 ext Cristian Daniel Stamateanu wrote:
> Hello,
> I have a class defined in C++ called RssItem and exposed to QML with
> qmlRegisterType<RssItem>(...). In Qml I am accessing an XmlListModel and
> inside the delegate I am creating a RssItem object for each item in the
> model that is displayed in a listview in qml. At some point when clicking
> on the item in list, I take the RssItem object and pass it back to C++. I
> was assuming that it is passed as a RssItem * but I get a segmentation
> fault. What am I missing?
> So the question is : C++ objects created in Qml are passed to C++ slots
> in what manner? How can they be accessed in C++. I am pretty sure I get a
> pointer in my Slot but it is not to RssItem.
Hi,
check the documentation on Script to C++ type conversion in
http://doc.qt.nokia.com/4.7-snapshot/scripting.html
As far as I remember, you can either use qScriptRegisterMetaType on your class
to make the conversion automatic or accept a 'const QScriptValue &' and
qobject_cast the result of toQObject() in your slot.
Cheers,
Christian
More information about the Qt-qml
mailing list