gpt4 book ai didi

python - PyQt4 在退出时崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 13:17:53 24 4
gpt4 key购买 nike

窗口将显示,但在退出时崩溃。 coredump 显示 QtGui4.dll 中发生了一些错误。

我的环境是PyQt4.10.4(Qt4.8.5) 32bit版本,Windows 7(64bit)。有任何线索或建议来查明发生了什么吗?非常感谢。

删除一个或多个控件则不会发生崩溃。好奇怪……

settings_window.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SettingWindow</class>
<widget class="QWidget" name="SettingWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>465</width>
<height>439</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>50</x>
<y>350</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>180</x>
<y>350</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>40</x>
<y>170</y>
<width>54</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>label</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_3">
<property name="geometry">
<rect>
<x>110</x>
<y>170</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>40</x>
<y>230</y>
<width>54</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_4">
<property name="geometry">
<rect>
<x>120</x>
<y>220</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_4">
<property name="geometry">
<rect>
<x>140</x>
<y>300</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>CheckBox</string>
</property>
</widget>
<widget class="QLabel" name="label_11">
<property name="geometry">
<rect>
<x>120</x>
<y>190</y>
<width>54</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QLabel" name="label_12">
<property name="geometry">
<rect>
<x>130</x>
<y>250</y>
<width>54</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>40</x>
<y>100</y>
<width>56</width>
<height>14</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>label</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>40</x>
<y>20</y>
<width>163</width>
<height>40</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>label</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>checkbox</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>checkbox</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

设置窗口.py

#-*- coding: utf-8 -*-

import sys
from PyQt4.QtGui import qApp, QDialog, QApplication
from ui_settings_window import Ui_SettingWindow

class SettingWindow(QDialog, Ui_SettingWindow):
def __init__(self):
super(SettingWindow, self).__init__()
self.setupUi(self)

if __name__ == "__main__":
app = QApplication(sys.argv)
window = SettingWindow()
window.show()
sys.exit(app.exec_())

最佳答案

sip.setdestroyonexit(False) 解决了我的问题。这将是 pyqt 退出时崩溃的最终答案。 pyqt document说:

When the Python interpreter exits PyQt4 (by default) calls the C++ destructor of all wrapped instances that it owns. This happens in a random order and can therefore cause the interpreter to crash. This behavior can be disabled by calling the sip.setdestroyonexit() function.

PyQt5 always calls sip.setdestroyonexit() automatically.

另一个引用应该是这个 post ,pyqt的作者讲了sip.setdestroyonexit()。

关于python - PyQt4 在退出时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23565702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com