title: How to render in Qt3D in standard GUI application?
body: <p>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.</p>
  <p>Basically what I want is a little rendering widget for my Qt5 Gui application.</p>
  <p>I've looked into Qtgl widget, but I really want to use the scene management abilities of Qt3D.</p>
  <p>How can I render as a sub window inside of a qt Gui window?</p>
  <p>Is this possible?</p>
  <p><strong>Update</strong></p>
  <p>So I added this to my MainWindow.cpp It is loosely based off of this <a href="https://www.qt.io/blog/2013/02/19/introducing-qwidgetcreatewindowcontainer" rel="nofollow noreferrer">https://www.qt.io/blog/2013/02/19/introducing-qwidgetcreatewindowcontainer</a></p>
  <pre><code>LoadModelView *view = new LoadModelView(); //Crashes on this. Will not compile with
                                             // LoadModelView(this) 
  
      QWidget *container = QWidget::createWindowContainer(view);
      container-&gt;setFocusPolicy(Qt::TabFocus);
  
      ui-&gt;gridLayout-&gt;addWidget(container);
  </code></pre>
  <p>which seems right.</p>
  <p>my load_model.cpp begins like this:</p>
  <pre><code>#include &quot;qglmaterialcollection.h&quot;
  #include &quot;qglmaterial.h&quot;
  #include &quot;qglscenenode.h&quot;
  #include &quot;qgllightmodel.h&quot;
  #include &quot;qglabstractscene.h&quot;
  #include &lt;QtGui/qmatrix4x4.h&gt;
  
  #include &lt;QPropertyAnimation&gt;
  #include &lt;QtCore/qmath.h&gt;
  
  #define DEGREE_TO_RAD (3.1415926/180.0)
  
  LoadModelView::LoadModelView(QWindow *parent)
      : QGLView(parent)
      , m_pSTLScene(0)
  {
      loadModels();
  
      camera()-&gt;setCenter(QVector3D(0, 0, 0));
      camera()-&gt;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-&gt;setStandardEffect(QGL::LitMaterial);
      painter-&gt;setFaceColor(QGL::AllFaces,QColor(170,202,0));
  
      painter-&gt;modelViewMatrix() = camera()-&gt;modelViewMatrix() * stlWorld;
  
      m_pSTLScene-&gt;mainNode()-&gt;draw(painter);
  }
  
  void FixNodesRecursive(int matIndex, QGLSceneNode* pNode)
  {
      if (pNode) {
          pNode-&gt;setMaterialIndex(matIndex);
         // pNode-&gt;setEffect(QGL::FlatReplaceTexture2D);
          foreach (QGLSceneNode* pCh, pNode-&gt;children()) {
              FixNodesRecursive(matIndex, pCh);
          }
      }
  }
  
  void LoadModelView::loadModels()
  {
      {
          m_pSTLScene = QGLAbstractScene::loadScene(QLatin1String(&quot;:/models/Sheep.stl&quot;), QString(),&quot;CorrectNormals CorrectAcute&quot;);
          Q_ASSERT(m_pSTLScene!=0);
          QGLMaterial *mat = new QGLMaterial;
          mat-&gt;setAmbientColor(QColor(170,202,0));
          mat-&gt;setDiffuseColor(QColor(170,202,0));
          mat-&gt;setShininess(128);
  
          QGLSceneNode* pSTLSceneRoot = m_pSTLScene-&gt;mainNode();
          int matIndex = pSTLSceneRoot-&gt;palette()-&gt;addMaterial(mat);
          pSTLSceneRoot-&gt;setMaterialIndex(matIndex);
          pSTLSceneRoot-&gt;setEffect(QGL::FlatReplaceTexture2D);
          FixNodesRecursive(matIndex,pSTLSceneRoot);
      }
  }
  </code></pre>
  <p>It crashes with:</p>
  <blockquote>
  <p>This application has requested the runtime to terminate it in an unusual way.</p>
  </blockquote>
  <p>And in the qt application output:</p>
  <blockquote>
  <p>Invalid parameter passed to C runtime function.</p>
  </blockquote>
  <p><strong>EDIT Added the rest of the class in question</strong></p>
  <p>I notice that in the example I am adapting <a href="https://github.com/Distrotech/qt3d/blob/master/tutorials/qt3d/penguin/main.cpp" rel="nofollow noreferrer">https://github.com/Distrotech/qt3d/blob/master/tutorials/qt3d/penguin/main.cpp</a> the window is initialized by saying:</p>
  <pre><code>LoadModelView view;
  </code></pre>
  <p>However, saying</p>
  <pre><code>LoadModelView *view = new LoadModelView(this)
  </code></pre>
  <p>crashes</p>