Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How can i set QdeclarativeEngine to QDeclarativeView ?
Forum Updated to NodeBB v4.3 + New Features

How can i set QdeclarativeEngine to QDeclarativeView ?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 4 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aabc
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DenisKormalev
        wrote on last edited by
        #3

        It's not allowed. Maybe you can elaborate why you need it and we will try to find other way to solve your problem?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          baysmith
          wrote on last edited by
          #4

          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.

          Nokia Certified Qt Specialist.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved