# QVTKOpenGLNativeWidget vkt9+qt5 framebuffer errors when using setParent

**URL:** https://discourse.vtk.org/t/qvtkopenglnativewidget-vkt9-qt5-framebuffer-errors-when-using-setparent/8645
**Category:** Support
**Created:** [June 2, 2022, 1:18pm UTC](https://discourse.vtk.org/t/qvtkopenglnativewidget-vkt9-qt5-framebuffer-errors-when-using-setparent/8645 "2022-06-02T13:18:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Michal\_Chlebiej](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michal_chlebiej/32/5260_2.png) [@Michal\_Chlebiej](https://discourse.vtk.org/u/Michal_Chlebiej)
#### Post date: [June 2, 2022, 1:18pm UTC](https://discourse.vtk.org/t/qvtkopenglnativewidget-vkt9-qt5-framebuffer-errors-when-using-setparent/8645/1 "2022-06-02T13:18:10Z")

</div>

Hi,

I’m trying to migrate my code from Vtk 8.2 to 9.1 using QT 5.15. My main problem is VTK+QT widget. I’ve been using my own VTKQT widget implementation for some years based on QVTKOpenGLNativeWidget.  
After updating to VTK9.1 I can create a stand-alone widget (without a parent) and it works fine. But when I try to reparent using “setParent” QT method (as I did without any problems with 8.2) to change the layout in my application it throws “failed at glDeleteFramebuffers 16 Opengl errors detected” and application crashes.

I would be grateful for any tips.

---

<div class="post-metadata">

### Author: ![joinvar](https://discourse.vtk.org/user_avatar/discourse.vtk.org/joinvar/32/7297_2.png) [@joinvar](https://discourse.vtk.org/u/joinvar)
#### Post date: [August 22, 2023, 3:29am UTC](https://discourse.vtk.org/t/qvtkopenglnativewidget-vkt9-qt5-framebuffer-errors-when-using-setparent/8645/2 "2023-08-22T03:29:54Z")

</div>

@Michal_Chlebiej hi,michal,has this issue been resolved? I’ve encountered the same problem. My Qt version is 6.5.2, and VTK version is 9.2.6.Below is my minimal code.

```auto
qDebug() << "onPushButton";
QWidget* centerWidget = this->centralWidget();
QVBoxLayout* vLayout = nullptr;
QLayout* layout = centerWidget->layout();
if (layout)
{
    vLayout = qobject_cast<QVBoxLayout*>(layout);
}
else
{
    vLayout = new QVBoxLayout();
    centerWidget->setLayout(vLayout);
}
QWidget* parentwidget1 = new QWidget();
QVTKOpenGLNativeWidget* qvtkWidget = new QVTKOpenGLNativeWidget();
QVBoxLayout* vlayout_sub1 = new QVBoxLayout();

vlayout_sub1->addWidget(qvtkWidget);
parentwidget1->setLayout(vlayout_sub1);
vLayout->addWidget(parentwidget1);
parentwidget1->show();

QWidget* parentwidget2 = new QWidget();

QVBoxLayout* vlayout_sub2 = new QVBoxLayout();

vlayout_sub2->addWidget(qvtkWidget);
parentwidget2->setLayout(vlayout_sub2);

```

The line parentwidget1-\>show(); is important, if not, it will not appear the error.

Additionally, I only encountered this issue in debug mode. In release mode, with the same code, there are no errors.

---

<div class="post-metadata">

### Author: ![joinvar](https://discourse.vtk.org/user_avatar/discourse.vtk.org/joinvar/32/7297_2.png) [@joinvar](https://discourse.vtk.org/u/joinvar)
#### Post date: [August 22, 2023, 6:15am UTC](https://discourse.vtk.org/t/qvtkopenglnativewidget-vkt9-qt5-framebuffer-errors-when-using-setparent/8645/3 "2023-08-22T06:15:25Z")

</div>

I solved the problem just now ! We should resource sharing between the Opengl contexts, and add just one line code before instantiating the QApplication like below:

```auto
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);

```

and now I am no longer encountering this error.

---

<div class="post-metadata">

### Author: ![Michal\_Chlebiej](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michal_chlebiej/32/5260_2.png) [@Michal\_Chlebiej](https://discourse.vtk.org/u/Michal_Chlebiej)
#### Post date: [October 11, 2023, 7:07am UTC](https://discourse.vtk.org/t/qvtkopenglnativewidget-vkt9-qt5-framebuffer-errors-when-using-setparent/8645/4 "2023-10-11T07:07:57Z")

</div>

Thanks a lot! It fixed my warnings too!

---

<div class="post-metadata">

### Author: ![EeuweVandyke](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/e/57b2e6/32.png) [@EeuweVandyke](https://discourse.vtk.org/u/EeuweVandyke)
#### Post date: [July 25, 2025, 7:51am UTC](https://discourse.vtk.org/t/qvtkopenglnativewidget-vkt9-qt5-framebuffer-errors-when-using-setparent/8645/5 "2025-07-25T07:51:02Z")

</div>

Thanx! I didn’t get the errors mentioned above, but this fix did tackle the problem: when reparenting the QVTKOpenGLNativeWidget (nothing was ever repainted again, all OpenGL stuff was black)
