How can i set QdeclarativeEngine to QDeclarativeView ?
-
QDeclarativeView creates QDeclarativeEngine for you. Thats the engine you get when you call engine(). I don't think you are allowed to set engine to QDeclarativeView.
-
It's not allowed. Maybe you can elaborate why you need it and we will try to find other way to solve your problem?
-
Although you can't set the engine on the QDeclarativeView, you can directly use a combination of the QDeclarativeEngine, QDeclarativeContext, and QGraphicsView.
@
static QDeclarativeEngine *engine = new QDeclarativeEngine;
static QDeclarativeComponent component(engine, QUrl::fromLocalFile("main.qml"));QGraphicsView *viewer = new QGraphicsView; viewer->setScene(new QGraphicsScene); QDeclarativeContext *context = new QDeclarativeContext(engine); QGraphicsObject *object = qobject_cast<QGraphicsObject*>(component.create(context)); viewer->scene()->addItem(object);
@
If called multiple times, the above code snippet uses a single engine and component to create multiple views each with their own context and instance of the component.