Skip to content

Commit 42aff4c

Browse files
committed
Another weird decision from Copilot
It says QOpenGLWidget does not have aboutToBeDestroyed. It says it is in QGLWidget. It isn't - testing with pyqt5 version (glwidget_abouttobedestroyed.py) does not work. Okay, reading the comment again - it says it is in QGLWidget in PySide1 and PyQt4(!).
1 parent 0037925 commit 42aff4c

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

glwidget_abouttobedestroyed.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from PyQt5.QtWidgets import QApplication, QMainWindow
2+
from PyQt5.QtOpenGL import QGLWidget
3+
from PyQt5.QtCore import pyqtSlot
4+
import sys
5+
6+
class MyOpenGLWidget(QGLWidget):
7+
def __init__(self, parent=None):
8+
super().__init__(parent)
9+
# Connect the aboutToBeDestroyed signal to your cleanup slot
10+
self.aboutToBeDestroyed.connect(self.cleanupGL)
11+
12+
@pyqtSlot()
13+
def cleanupGL(self):
14+
# This will be called just before the GL context is destroyed
15+
print("OpenGL context is about to be destroyed. Clean up GPU resources here.")
16+
17+
def initializeGL(self):
18+
print("initializeGL: OpenGL context created.")
19+
20+
def resizeGL(self, w, h):
21+
print(f"resizeGL: {w}x{h}")
22+
23+
def paintGL(self):
24+
pass
25+
26+
class MainWindow(QMainWindow):
27+
def __init__(self):
28+
super().__init__()
29+
self.setCentralWidget(MyOpenGLWidget(self))
30+
31+
def main():
32+
app = QApplication(sys.argv)
33+
window = MainWindow()
34+
window.show()
35+
sys.exit(app.exec())
36+
37+
if __name__ == "__main__":
38+
main()

openglwidget_abouttobedestroyed.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ class MyOpenGLWidget(QOpenGLWidget):
77
def __init__(self, parent=None):
88
super().__init__(parent)
99
# Connect the aboutToBeDestroyed signal to your cleanup slot
10-
self.aboutToBeDestroyed.connect(self.cleanupGL)
10+
#self.aboutToBeDestroyed.connect(self.cleanupGL)
1111

12-
@pyqtSlot()
13-
def cleanupGL(self):
14-
# This will be called just before the GL context is destroyed
15-
print("OpenGL context is about to be destroyed. Clean up GPU resources here.")
12+
#@pyqtSlot()
13+
#def cleanupGL(self):
14+
# # This will be called just before the GL context is destroyed
15+
# print("OpenGL context is about to be destroyed. Clean up GPU resources here.")
16+
17+
def closeEvent(self, event):
18+
print("Widget is about to be destroyed")
19+
super().closeEvent(event)
1620

1721
def initializeGL(self):
1822
print("initializeGL: OpenGL context created.")

0 commit comments

Comments
 (0)