Skip to content

Commit b05da0a

Browse files
authored
Merge pull request #1947 from HEXRD/python-update-fixes
Python update fixes
2 parents 7129b1c + 6c10cbd commit b05da0a

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

hexrdgui/main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import atexit
2+
import gc
13
import os
24
import signal
35
import sys
@@ -70,5 +72,39 @@ def apply_parsed_args_to_hexrd_config(parsed_args):
7072
setattr(hexrd_config, v, getattr(parsed_args, k))
7173

7274

75+
def cleanup_widgets():
76+
"""Clean up Qt widgets before Python shutdown
77+
78+
This is necessary for newer versions of Qt (>= 6.8),
79+
because there are some kinds of conflicts between Qt and
80+
the Python's cleanup systems that can cause crashes.
81+
82+
This fix ensures that all Qt objects are deleted and cleaned
83+
up before Python performs its cleanup.
84+
"""
85+
app = QApplication.instance()
86+
if app:
87+
# Close all top-level widgets
88+
for widget in app.topLevelWidgets()[:]:
89+
try:
90+
widget.close()
91+
widget.deleteLater()
92+
except RuntimeError:
93+
# Already deleted by Qt - that's fine
94+
pass
95+
96+
try:
97+
# Process events to ensure deleteLater() is executed
98+
app.processEvents()
99+
except RuntimeError:
100+
pass
101+
102+
# Force garbage collection
103+
gc.collect()
104+
105+
106+
# Register cleanup to run before Python's atexit handlers
107+
atexit.register(cleanup_widgets)
108+
73109
if __name__ == '__main__':
74110
main()

hexrdgui/select_items_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def create_label(self, v):
5353

5454
def create_checkbox(self, v):
5555
cb = QCheckBox(self.ui.table)
56-
cb.setChecked(v)
56+
cb.setChecked(bool(v))
5757
cb.toggled.connect(self.checkbox_toggled)
5858
self.checkboxes.append(cb)
5959
return self.create_table_widget(cb)

0 commit comments

Comments
 (0)