June 26, 2012

paxl paxl
Lab Rat
14 posts

Qt3D - Retrieving Qml Viewport Element as C++ Object

 

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 :

  1. bool    QmlViewManager::initView()
  2. {
  3.     // SET STARTING QML FILE
  4.     this->viewer->setSource(QUrl::fromLocalFile("qml/Tepee3DSampleApp/main.qml"));
  5.     this->viewer->show();
  6.       //CONTROLLER BETWEEN QML VIEW AND MODELS
  7.     this->viewer->rootContext()->setContextProperty("controller", this);
  8.     // GET ROOT QML OBJECT
  9.     this->rootQmlObject = this->viewer->rootObject();
  10.     // SET SCREESIZE IN ROOT OBJECT
  11.     this->rootQmlObject->setProperty("width", this->desktopWidget->screenGeometry(-1).width());
  12.     this->rootQmlObject->setProperty("height", this->desktopWidget->screenGeometry(-1).height());
  13.     // SHOW QML FILE IN FULLSCREEN
  14.     QObject *tmpObj;
  15.     if ((tmpObj = this->rootQmlObject->findChild<QObject *>("viewport")))
  16.     {
  17.         this->viewport = (Viewport*)tmpObj;
  18.         std::cout << "ViewPort found" << std::endl;
  19.     }
  20.     if ((tmpObj = this->rootQmlObject->findChild<QObject  *>("root3dObject")))
  21.     {
  22.         this->root3dObject = (QQuickItem*)tmpObj;
  23.         std::cout << "Root3dObject found" << std::endl;
  24.     }
  25. }

Any help will be very appreciated.

Thanks

1 reply

November 30, 2012

paxl paxl
Lab Rat
14 posts

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.

 
  ‹‹ QSqlite Application runs on my computer but not on client computers: Drivers not loaded.      ContextMenu in QTreeView ››

You must log in to post a reply. Not a member yet? Register here!