[Qt-qml] Using QML canvas from C++, like QGraphicsView
Alan Alpert
alan.alpert at nokia.com
Wed Jan 19 00:08:37 CET 2011
On Wednesday, January 19, 2011 12:50:41 am ext Ville M. Vainio wrote:
> Let's say we have a guy that wants to write a 2D game with C++. He
> likes Qt, not OpenGL so much, and is considering two options - QGV and
> QML. He is not interested in doing anything in Javascript, so he's
> basically going to implement all the logic, animation etc. in C++
> side. He still wants to reside on QML canvas so it will be simple to
> extend the game with nice menus and secondary views. The glorious
> QGraphicsScene speedups and OpenGL effects coming up in the pipeline
> also fascinate our protagonist.
>
> So, he will basically be manipulating all the QML elements by
> discovering the QDeclarativeItem's from the QML tree and fiddling with
> their properties directly. Or something.
>
> How bad a performance hit would this be, compared to just using
> QGraphicsView? Would it be in any way signifant?
>
> (Let's forget all the hacks where you create a QGV scene and embed it
> inside QML for the purposes of this discussion)
It sounds like he should use a mix. You can have a QGraphicsScene that loads
QML files for the menus and other frills and yet has QGraphicsObjects
controlled from C++ as the main feature. And you can expose those
QGraphicsObjects to the QML files as well, without needed them to have been
created in QML to start with.
QDeclarativeComponent can give you a QGraphicsObject tree from a QML file,
ready to embed within a QGV scene. And doing it that way around is not a hack
;) .
--
Alan Alpert
Software Engineer
Nokia, Qt Development Frameworks
More information about the Qt-qml
mailing list