[PyQt] Segfault when trying
newDoc.setDocumentLayout(QtGui.QPlainTextDocumentLayout(newDoc))
GT6
gt6 at gmx.net
Mon Feb 2 02:37:13 GMT 2009
Hi there.
When running the below sample script, and clicking the button, it will
segfault, and I don't understand why or how. I've overwritten a function
in QPlainTextEdit and it should create a new document, set the
PlainTextDocumentLayout and then set the document on the QPlainTextEdit
widget. The important part is this (1st way):
newDoc = QtGui.QTextDocument()
newDoc.setDocumentLayout(QtGui.QPlainTextDocumentLayout(newDoc))
self.setDocument(newDoc)
The above segfaults. I also tried this (2nd way):
newDoc = QtGui.QTextDocument()
newDoc.setDocumentLayout(self.documentLayout())
self.setDocument(newDoc)
This one doesn't segfault, but I get this error:
AttributeError: documentLayout
Apart from that, I tried this third option (3rd way):
newDoc = QtGui.QTextDocument()
newDoc.setDocumentLayout(QtGui.QPlainTextDocumentLayout.__init__(newDoc))
self.setDocument(newDoc)
with the only difference from the first one being that __init__ is
called explicitly instead of expecting it to be defaultet. This one
_doesn't_ segfault, but gives this error:
QPlainTextEdit::setDocument: Document set does not support
QPlainTextDocumentLayout
Which makes no sense as not calling __init__ directly shouldn't be any
different than calling it explicitly. So, does anyone have any idea why
this is happening? Do you have a bug tracker?
Thanks and Regards,
Carl
Here's the complete code ready to be executed. I've commented out ways 2
and 3, you can comment the first one and try them out:
#!/usr/bin/python
import sys
from PyQt4 import QtGui, QtCore
class TextEditEnter(QtGui.QPlainTextEdit):
def __init__(self, parent=None):
QtGui.QPlainTextEdit.__init__(self, parent)
def plzsegfault(self):
newDoc = QtGui.QTextDocument()
newDoc.setDocumentLayout(QtGui.QPlainTextDocumentLayout(newDoc))
# First way
#newDoc.setDocumentLayout(self.documentLayout()) # Second way
#newDoc.setDocumentLayout(QtGui.QPlainTextDocumentLayout.__init__(newDoc))
# Third way
self.setDocument(newDoc)
class MainWidget(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(400, 400, 200, 200)
self.setWindowTitle('sample')
grid = QtGui.QGridLayout()
grid.setSpacing(10)
self.textField = TextEditEnter()
self.bt = QtGui.QPushButton('Segfault!', self)
grid.addWidget(self.bt, 0, 0)
grid.addWidget(self.textField, 1, 0)
self.setLayout(grid)
self.connect(self.bt, QtCore.SIGNAL('clicked()'),
self.textField.plzsegfault)
app = QtGui.QApplication(sys.argv)
mainWidget = MainWidget()
mainWidget.show()
sys.exit(app.exec_())
More information about the PyQt
mailing list