I enjoy using Qt3D, but all of the examples I see for it are full window applications. What I can't understand from the examples is how to add a qt3d rendering window to a regular qt gui application.
Basically what I want is a little rendering widget for my Qt5 Gui application.
I've looked into Qtgl widget, but I really want to use the scene management abilities of Qt3D.
How can I render as a sub window inside of a qt Gui window?
Is this possible?
Update
So I added this to my MainWindow.cpp It is loosely based off of this http://blog.qt.digia.com/blog/2013/02/19/introducing-qwidgetcreatewindowcontainer/
LoadModelView *view = new LoadModelView(); //Crashes on this. Will not compile with // LoadModelView(this) QWidget *container = QWidget::createWindowContainer(view); container->setFocusPolicy(Qt::TabFocus); ui->gridLayout->addWidget(container);
which seems right.
my load_model.cpp begins like this:
#include "qglmaterialcollection.h" #include "qglmaterial.h" #include "qglscenenode.h" #include "qgllightmodel.h" #include "qglabstractscene.h" #include <QtGui/qmatrix4x4.h> #include <QPropertyAnimation> #include <QtCore/qmath.h> #define DEGREE_TO_RAD (3.1415926/180.0) LoadModelView::LoadModelView(QWindow *parent) : QGLView(parent) , m_pSTLScene(0) { loadModels(); camera()->setCenter(QVector3D(0, 0, 0)); camera()->setEye(QVector3D(0, 4, 10)); } LoadModelView::~LoadModelView() { delete m_pSTLScene; } void LoadModelView::paintGL(QGLPainter *painter) { QMatrix4x4 stlWorld; stlWorld.setToIdentity(); stlWorld.scale(0.1); stlWorld.translate(QVector3D(2.0,0.0,0.0)); painter->setStandardEffect(QGL::LitMaterial); painter->setFaceColor(QGL::AllFaces,QColor(170,202,0)); painter->modelViewMatrix() = camera()->modelViewMatrix() * stlWorld; m_pSTLScene->mainNode()->draw(painter); } void FixNodesRecursive(int matIndex, QGLSceneNode* pNode) { if (pNode) { pNode->setMaterialIndex(matIndex); // pNode->setEffect(QGL::FlatReplaceTexture2D); foreach (QGLSceneNode* pCh, pNode->children()) { FixNodesRecursive(matIndex, pCh); } } } void LoadModelView::loadModels() { { m_pSTLScene = QGLAbstractScene::loadScene(QLatin1String(":/models/Sheep.stl"), QString(),"CorrectNormals CorrectAcute"); Q_ASSERT(m_pSTLScene!=0); QGLMaterial *mat = new QGLMaterial; mat->setAmbientColor(QColor(170,202,0)); mat->setDiffuseColor(QColor(170,202,0)); mat->setShininess(128); QGLSceneNode* pSTLSceneRoot = m_pSTLScene->mainNode(); int matIndex = pSTLSceneRoot->palette()->addMaterial(mat); pSTLSceneRoot->setMaterialIndex(matIndex); pSTLSceneRoot->setEffect(QGL::FlatReplaceTexture2D); FixNodesRecursive(matIndex,pSTLSceneRoot); } }
It crashes with: This application has requested the runtime to terminate it in an unusual way.
and in the qt application output: Invalid parameter passed to C runtime function.
EDIT Added the rest of the class in question
I notice that in the example I am adapting http://doc.qt.digia.com/qt-quick3d-snapshot/qt3d-penguin-main-cpp.html the window is initialized by saying:
LoadModelView view;
However, saying
LoadModelView *view = new LoadModelView(this)
crashes