【发布时间】:2013-07-04 12:37:54
【问题描述】:
我正在使用 Mark Summerfield 的 Rapid GUI 编程书,它是为 PyQt4 编写的,我正在使用 PyQt5。有些事情肯定是不同的。
谁能看到为什么在我运行 Ubuntu 13.04 的 Linux 机器上失败了?它在 Mint 15 上运行,但有时会以分段错误结束。我认为这与 PyQt4 和 PyQt5 之间的区别有关,我一直在 qt-project.org 网站上研究 C++ 实现。到目前为止,我可以看出 QVBoxLayout 确实继承自 QDialog,并且它确实具有 setLayout 函数。但是,注释掉 _init_ 函数中的最后一行将允许程序运行而不会崩溃,而且不会向 QDialog 框添加任何小部件。
import sys
import PyQt5.QtCore
import PyQt5.QtGui
import PyQt5.QtWidgets
class Form(PyQt5.QtWidgets.QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.browser = PyQt5.QtWidgets.QTextBrowser()
self.lineEdit = PyQt5.QtWidgets.QLineEdit("default statement here")
self.lineEdit.selectAll()
layout = PyQt5.QtWidgets.QVBoxLayout()
layout.addWidget(self.browser)
layout.addWidget(self.lineEdit)
self.setLayout(layout) # <--- program seems to crash here
app = PyQt5.QtWidgets.QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
我收到这样的初始错误消息,重复了大约 10 次:
(python3:9896): Gtk-CRITICAL **: IA__gtk_widget_style_get: assertion `GTK_IS_WIDGET (widget)' failed
然后是下面的代码块,一直重复,直到我终止程序:
QXcbShmImage: shmget() failed (22) for size -524284 (65535x65535)
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
QPainter::translate: Painter not active
QPainter::save: Painter not active
QPainter::setClipRect: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::restore: Unbalanced save/restore
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
QPainter::setClipRect: Painter not active
[etc, etc, etc...]
【问题讨论】:
-
其实好像可以在这里找到解决方案:stackoverflow.com/questions/14606396/…
-
似乎是 Ubuntu 上 GTKStyle 的一个错误。
标签: pyqt qt5 python-3.3 qdialog pyqt5