C++ and QML : Using QDeclarativeEngine instead of QDeclarativeView
I'm trying to use the QDeclarativeEngine to create my view instead of the QDeclarativeView, but the view doesn't appear. The examples in the doc always describe something like this :
QDeclarativeContext *windowContext = new QDeclarativeContext(engine.rootContext());
QDeclarativeComponent component(&engine, "main.qml");
QObject *window = component.create(windowContext);
Do I need to put the window QObject in a QGraphicsView also ? or Am I doing something wrong ?
Thanks for your help
QDeclarativeEngine and QDeclarativeView are not equivalent.
QDeclarativeView inherits QGraphicsView and encapsulates a QGraphicsScene, QDeclarativeEngine, creates a context. So, QDeclarativeView is a convenience class which creates the basic structure so you can easily display a qml file with a single setSource().
Answering your question: You need to put this window object in a QGraphicsScene as described in "this part of the docs":http://doc.qt.nokia.com/4.7/qml-integration.html#integrating-with-a-qgraphicsview-based-ui . Attention to the qobject_cast to QGraphicsObject.