PyQt5 setLayout函数导致程序崩溃?

时间:2013-07-06 17:22:52

标签: pyqt qt5 python-3.3 qdialog pyqt5

我正在使用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...]

1 个答案:

答案 0 :(得分:1)

问题是QTextBrowser的大小。

看到这个错误:

https://bugreports.qt-project.org/browse/QTBUG-32527