gpt4 book ai didi

python - 退出 python 时为 "StackHash_0a9e error"

转载 作者:太空宇宙 更新时间:2023-11-04 01:28:25 25 4
gpt4 key购买 nike

我是python初学者,写了一个小程序,退出程序的时候,有时候(超过 50% 的概率)它显示错误。这是在我退出程序后才发生的。你能帮我看看我的代码有什么问题吗?

非常感谢。

ps:我在win7 sp1 x64上使用python3.3和pyqt4

错误:

 问题签名:
问题事件名称: BEX
应用程序名: python.exe
应用程序版本: 0.0.0.0
应用程序时间戳: 5150c40a
故障模块名称: StackHash_0a9e
故障模块版本: 0.0.0.0
故障模块时间戳: 00000000
异常偏移: 00388100
异常代码: c0000005
异常数据: 00000008
OS 版本: 6.1.7601.2.1.0.256.1
区域设置 ID: 2052
其他信息 1: 0a9e
其他信息 2: 0a9e372d3b4ad19135b953a78882e789
其他信息 3: 0a9e
其他信息 4: 0a9e372d3b4ad19135b953a78882e789

控制台返回:

进程结束,退出代码为 -1073741819

主要代码:

import urllib
import http.cookiejar
import time
import sys
from bs4 import BeautifulSoup
from PyQt4 import QtGui
from PyQt4 import QtCore


class BaiduMainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(BaiduMainWindow, self).__init__(parent)
self.initUI()

def initUI(self):
self.centralwidget = BaiduWidget(self)
self.setCentralWidget(self.centralwidget)
self.resize(600, 400)
self.move(QtGui.QApplication.desktop().screen().rect().center() - self.rect().center())
self.statusBar().showMessage('Ready')


class BaiduWidget(QtGui.QWidget):
def __init__(self, parent):
super(BaiduWidget, self).__init__(parent)
self.initUI()

def initUI(self):
lb = QtGui.QLabel('Search Word')
self.keyWordEdit = QtGui.QLineEdit()
self.OKButton = QtGui.QPushButton('Search')
self.containFilter = QtGui.QLineEdit()
self.exceptFilter = QtGui.QLineEdit()
self.result = QtGui.QTextBrowser()

spacerItem = QtGui.QSpacerItem(30, 50)

grid = QtGui.QGridLayout()
grid.setSpacing(10)
grid.addItem(spacerItem, 0, 0)
grid.addWidget(lb, 1, 0)
grid.addWidget(self.keyWordEdit, 2, 0)
grid.addWidget(self.OKButton, 5, 0)
grid.addItem(spacerItem, 7, 0)
grid.addWidget(self.result, 0, 1, 8, 1)
grid.setColumnStretch(1, 4)
self.setLayout(grid)



if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
form = BaiduMainWindow()
form.show()
sys.exit(app.exec_())

最佳答案

问题是:spacerItem 已被添加到 grid 两次。当您退出程序时,该对象可能会被 Qt 释放两次。


def initUI(self):
lb = QtGui.QLabel('Search Word')
self.keyWordEdit = QtGui.QLineEdit()
self.OKButton = QtGui.QPushButton('Search')
self.containFilter = QtGui.QLineEdit()
self.exceptFilter = QtGui.QLineEdit()
self.result = QtGui.QTextBrowser()

spacerItem = QtGui.QSpacerItem(30, 50)

grid = QtGui.QGridLayout()
grid.setSpacing(10)
grid.addItem(<b>spacerItem</b>, 0, 0)
grid.addWidget(lb, 1, 0)
grid.addWidget(self.keyWordEdit, 2, 0)
grid.addWidget(self.OKButton, 5, 0)
grid.addItem(<b>spacerItem</b>, 7, 0)
grid.addWidget(self.result, 0, 1, 8, 1)
grid.setColumnStretch(1, 4)
self.setLayout(grid)

您应该使用两个 QSpacerItem


def initUI(self):
lb = QtGui.QLabel('Search Word')
self.keyWordEdit = QtGui.QLineEdit()
self.OKButton = QtGui.QPushButton('Search')
self.containFilter = QtGui.QLineEdit()
self.exceptFilter = QtGui.QLineEdit()
self.result = QtGui.QTextBrowser()

spacerItem = QtGui.QSpacerItem(30, 50)
<b>spacerItem2 = QtGui.QSpacerItem(30, 50)</b>

grid = QtGui.QGridLayout()
grid.setSpacing(10)
grid.addItem(spacerItem, 0, 0)
grid.addWidget(lb, 1, 0)
grid.addWidget(self.keyWordEdit, 2, 0)
grid.addWidget(self.OKButton, 5, 0)
grid.addItem(<b>spacerItem2</b>, 7, 0)
grid.addWidget(self.result, 0, 1, 8, 1)
grid.setColumnStretch(1, 4)
self.setLayout(grid)

关于python - 退出 python 时为 "StackHash_0a9e error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15849090/

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