python – PyQt4在退出时崩溃了

python – PyQt4在退出时崩溃了,第1张

概述窗口将显示,但在退出时崩溃. coredump显示QtGui4.dll发生了一些错误. 我的环境是PyQt4.10.4(Qt4.8.5)32位版本,Windows 7(64位).有任何线索或任何建议,以找出发生了什么?非常感谢. 删除一个或多个控件然后崩溃将不会发生.太奇怪了… settings_window.ui <?xml version="1.0" encoding="UTF-8"?><u 窗口将显示,但在退出时崩溃. coredump显示QtGui4.dll发生了一些错误.

我的环境是PyQt4.10.4(Qt4.8.5)32位版本,Windows 7(64位).有任何线索或任何建议,以找出发生了什么?非常感谢.

删除一个或多个控件然后崩溃将不会发生.太奇怪了…

settings_window.ui

<?xml version="1.0" enCoding="UTF-8"?><ui version="4.0"> <class>SettingWindow</class> <Widget  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  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  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  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  name="lineEdit_3">   <property name="geometry">    <rect>     <x>110</x>     <y>170</y>     <wIDth>113</wIDth>     <height>20</height>    </rect>   </property>  </Widget>  <Widget  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  name="lineEdit_4">   <property name="geometry">    <rect>     <x>120</x>     <y>220</y>     <wIDth>113</wIDth>     <height>20</height>    </rect>   </property>  </Widget>  <Widget  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  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  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  name="layoutWidget">   <property name="geometry">    <rect>     <x>40</x>     <y>100</y>     <wIDth>56</wIDth>     <height>14</height>    </rect>   </property>   <layout  name="formlayout_2">    <property name="fIEldGrowthPolicy">     <enum>qformlayout::AllNonFixedFIEldsGrow</enum>    </property>    <item row="0" column="0">     <Widget  name="label_2">      <property name="text">       <string>label</string>      </property>     </Widget>    </item>   </layout>  </Widget>  <Widget  name="layoutWidget">   <property name="geometry">    <rect>     <x>40</x>     <y>20</y>     <wIDth>163</wIDth>     <height>40</height>    </rect>   </property>   <layout  name="formlayout">    <property name="fIEldGrowthPolicy">     <enum>qformlayout::AllNonFixedFIEldsGrow</enum>    </property>    <item row="0" column="0">     <Widget  name="label">      <property name="text">       <string>label</string>      </property>     </Widget>    </item>    <item row="0" column="1">     <Widget  name="checkBox">      <property name="text">       <string>checkBox</string>      </property>     </Widget>    </item>    <item row="1" column="1">     <Widget  name="checkBox_2">      <property name="text">       <string>checkBox</string>      </property>     </Widget>    </item>   </layout>  </Widget> </Widget> <resources/> <connections/></ui>

settings_window.py

#-*- Coding: utf-8 -*-import sysfrom PyQt4.QtGui import qApp,QDialog,QApplicationfrom ui_settings_window import Ui_SettingWindowclass 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在退出时崩溃了全部内容,希望文章能够帮你解决python – PyQt4在退出时崩溃了所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1193109.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存