From the Python point of view, the example does not work (wrong imports for QVector3D/Qt3Window). The revised example without cleanup
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget
from PySide6.QtGui import QVector3D
from PySide6.Qt3DExtras import Qt3DExtras
from PySide6.Qt3DCore import Qt3DCore
class Simple3DWindow(Qt3DExtras.Qt3DWindow):
def __init__(self, parent=None):
super().__init__(parent)
self._root_entity = Qt3DCore.QEntity()
self.setRootEntity(self._root_entity)
self.camera().lens().setPerspectiveProjection(45.0, 16.0/9.0, 0.1, 1000.0)
self.camera().setPosition(QVector3D(0, 0, 20.0))
self.camera().setViewCenter(QVector3D(0, 0, 0))
def main():
app = QApplication(sys.argv)
main_window = QMainWindow()
main_window.setWindowTitle("Test QWindowContainer Segfault")
main_window.resize(800, 600)
display = Simple3DWindow()
container = QWidget.createWindowContainer(display) # β Problem here
main_window.setCentralWidget(container)
main_window.show()
result = QApplication.exec()
# QApplication will be automatically destroyed by PySide6 β SEGFAULT
return result
if __name__ == "__main__":
sys.exit(main())
does not show any crashes. There are some situations though in PySide, where an explicit synchronous cleanup or shutdown of graphics resources is required. This is then best done in an overridden closeEvent() of the top level window.
Also note that Qt3D is now deprecated.