Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt3D - Retrieving Qml Viewport Element as C++ Object
Forum Updated to NodeBB v4.3 + New Features

Qt3D - Retrieving Qml Viewport Element as C++ Object

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.4k 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.
  • P Offline
    P Offline
    paxl
    wrote on last edited by
    #1

    Hey guys,

    I've been messing around with Qt5 and Qt3D / Quick3D a bit but I getting stuck trying to retrieve my qml Viewport Element as a c++ Viewport object.
    I can't seem to find the Viewport class include which is not indicated in the documentation :
    http://qt-project.org/doc/qt-5.0/qml-viewport.html
    http://doc-snapshot.qt-project.org/5.0/viewport.html
    I don't know if it's because it's deprecated or on the contrary not finalized yet.

    Then I'd like to make sure I'm retrieving my object the right way so I've posted a sample of my code :

    @
    bool QmlViewManager::initView()
    {
    // SET STARTING QML FILE
    this->viewer->setSource(QUrl::fromLocalFile("qml/Tepee3DSampleApp/main.qml"));
    this->viewer->show();
    //CONTROLLER BETWEEN QML VIEW AND MODELS
    this->viewer->rootContext()->setContextProperty("controller", this);
    // GET ROOT QML OBJECT
    this->rootQmlObject = this->viewer->rootObject();
    // SET SCREESIZE IN ROOT OBJECT
    this->rootQmlObject->setProperty("width", this->desktopWidget->screenGeometry(-1).width());
    this->rootQmlObject->setProperty("height", this->desktopWidget->screenGeometry(-1).height());
    // SHOW QML FILE IN FULLSCREEN
    QObject *tmpObj;
    if ((tmpObj = this->rootQmlObject->findChild<QObject >("viewport")))
    {
    this->viewport = (Viewport
    )tmpObj;
    std::cout << "ViewPort found" << std::endl;
    }
    if ((tmpObj = this->rootQmlObject->findChild<QObject >("root3dObject")))
    {
    this->root3dObject = (QQuickItem
    )tmpObj;
    std::cout << "Root3dObject found" << std::endl;
    }
    }
    @

    Any help will be very appreciated.

    Thanks

    1 Reply Last reply
    0
    • P Offline
      P Offline
      paxl
      wrote on last edited by
      #2

      For those interested, you can't really retrieve a Viewport directly from qml as it is a QQuickItem. So either you retrieve it as a QQuickItem* and then try to insert your 3D items in it (not tested but it should work) or you do this on the qml side using loaders.

      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