2014-05-09 97 views
3

窗口將顯示,但在出口處墜毀。 coredump顯示在QtGui4.dll中發生了一些錯誤。PyQt4在出口處墜毀

我的環境是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> 

settings_window.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_()) 

回答

7

sip.setdestroyonexit(假)解決我的問題。這將是pyqt退出崩潰的最終答案。該pyqt document說:

當Python解釋器退出PyQt4的(默認)調用都包裹實例的C++ 析構函數,它擁有。這發生在 隨機順序中,因此可能導致解釋器崩潰。通過調用sip.setdestroyonexit() 函數,可以禁用此行爲 。

PyQt5總是自動調用sip.setdestroyonexit()。

另一個參考應該是這個post,pyqt的作者談論了sip.setdestroyonexit()。