How can i set QdeclarativeEngine to QDeclarativeView ?

  • In QDeclarativeView there is a const engine() method but there is no setEngine() method.
    How can i connect between my own QDeclarativeEngine and my own 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));


    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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.