# QQmlVTKPlugin window initialization from QML

**URL:** <https://discourse.vtk.org/t/qqmlvtkplugin-window-initialization-from-qml/7035>\
**Category:** Development\
**Created:** [November 1, 2021, 3:38pm UTC](https://discourse.vtk.org/t/qqmlvtkplugin-window-initialization-from-qml/7035 "2021-11-01T15:38:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julienchz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/julienchz/32/4106_2.png) [@Julienchz](https://discourse.vtk.org/u/Julienchz)\
**Post date:** [November 1, 2021, 3:38pm UTC](https://discourse.vtk.org/t/qqmlvtkplugin-window-initialization-from-qml/7035/1 "2021-11-01T15:38:38Z")

</div>

Hello,  
I am using the QQMLvtkPlugin in my Qt Quick app. To do that the vtk documentation give the following example :

```auto
  QQuickVTKRenderWindow::setupGraphicsBackend();
  QGuiApplication app(argc, argv);
 
  QQmlApplicaQtionEngine engine;
  engine.load(QUrl("qrc:///<qmlfile>.qml"));
 
  QObject* topLevel = engine.rootObjects().value(0);
  QQuickWindow* window = qobject_cast<QQuickWindow*>(topLevel);
 
  window->show();
 
  // Fetch the QQuick window using the standard object name set up in the constructor
  QQuickVTKRenderItem* qquickvtkItem = topLevel->findChild<QQuickVTKRenderItem*>("ConeView");

```

However, in my app I want to initialize my qquickvtkItem from my main.qml. In order to do that I have a singleton testQML wich allows me to create my scene:

```auto
ApplicationWindow {
    id: appWindow;
    readonly property SceneManage scene: TestQML.create(appWindow)
   ...

```

TestQML.create():

```auto
SceneManage *testQML::create(QQuickWindow *parent)
{
    SceneManage *scene = new SceneManage(parent);
    return scene;
}

```

But my app crashes when I do a window-\>show in the SceneManage constructor :

```auto
SceneManage::SceneManage(QObject *topLevel)
{
    window = qobject_cast<QQuickWindow *>(topLevel); // QQuickWindow window
    window->show();
    QQuickItem *item = topLevel->findChild<QQuickItem *>("3DViewer");
...

```

Does someone have a way to solve this problem ? (The solution of the documentation and mine give the same adresses for window and the QQuickVTKRenderItem, so these are the right object)  
Many thanks

---

<div class="post-metadata">

**Author:** ![Julienchz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/julienchz/32/4106_2.png) [@Julienchz](https://discourse.vtk.org/u/Julienchz)\
**Post date:** [November 2, 2021, 10:37am UTC](https://discourse.vtk.org/t/qqmlvtkplugin-window-initialization-from-qml/7035/2 "2021-11-02T10:37:30Z")

</div>

Solution : Don’t decide to show the window from c++ but only set visible parameter in QML.
