From kde-devel Thu Jun 09 11:20:04 2011 From: Sebastian =?iso-8859-1?q?K=FCgler?= Date: Thu, 09 Jun 2011 11:20:04 +0000 To: kde-devel Subject: Re: Communication between C++ and QML Message-Id: <201106091320.04552.sebas () kde ! org> X-MARC-Message: https://marc.info/?l=kde-devel&m=130761846112693 On Friday, June 03, 2011 23:12:03 Stefan Majewsky wrote: > I've been looking into QML again for kdegames. Some background: I > added a QDeclarativeImageProvider to feed images from libtagaro's > ThemeProvider into QML, and that mostly works (with an emphasis on > mostly; QTBUG-14900). Then I tried something more difficult: I wanted > to port a game from QML, and chose KNetwalk because it has its > algorithms split in an AbstractGrid class, which is subclassed for the > QGraphicsView representation. > > Now as far as I understand the (IMHO surprisingly sparse) > QtDeclarative module documentation, the main gateway for transferring > information between C++ and QML is > declarativeView->engine()->rootContext()->setContextObject(). QML > retrieves data from the properties of this object and the subobjects > which it references, and invokes via JavaScript functions in this > object to propagate user input to the C++ layer. > > Is this correct? If so, I get a feeling that it would require a > potentially epic amount of boilerplate to make my already > interface-agnostic data available to QML. Can I do anything to make > this task simpler? You could use Plasma::DataEngine on the C++ side, and then get at the data in your QML code using PlasmaCore.DataSource. That's how we generally do it in Plasma. Cheers, -- sebas http://www.kde.org | http://vizZzion.org | GPG Key ID: 9119 0EF9 >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<