[PyKDE] RE: strange bug in PyQt or python?
Tad E. Smith
tcsmithfamily at home.com
Thu Jul 19 09:37:20 BST 2001
Gerard Vermeulen wrote:
>
> Hi,
>
> The following 30-line program (python-2.1, PyQt/sip-2.5pre1, Qt-2.2.1)
> shows a bug, that goes away if I comment out line 14 and
> uncomment line 15
>
> --
> #!/usr/bin/env python
>
> import sys
> from qt import *
>
> class Item(QListViewItem):
> def __init__(self, parent, value):
> QListViewItem.__init__(self, parent)
> self.value = value
>
> def text(self, column):
> if column == 0:
> print self.value[0]
> return "%4d: %5d %8.2f %8.2f" % self.value[0] # this fails
> #return "%4d: %5d %s %s" % self.value[0] # this works
> elif column == 1: return "[%5d, %5d)" % self.value[1]
> else: return ""
>
> list = [((1, 520, 3.14, 2.72), (13, 17)), ((2, 520, 2.72, 3.14), (37, 43))]
> for item in list:
> print "%4d: %5d %8.2f %8.2f" % item[0]
>
> app = QApplication(sys.argv)
> listView = QListView()
> app.setMainWidget(listView)
> listView.setCaption('Pourquoi?')
> listView.addColumn('Settings')
> listView.addColumn('Zoom')
> for item in list:
> Item(listView, item)
> listView.show()
> app.exec_loop()
> --
> It crashes with
> --
> [packer at taco python]$ python bug.py
> 1: 520 3.14 2.72
> 2: 520 2.72 3.14
> (2, 520, 2.7200000000000002, 3.1400000000000001)
> (1, 520, 3.1400000000000001, 2.7200000000000002)
> (2, 520, 2.7200000000000002, 3.1400000000000001)
> (1, 520, 3.1400000000000001, 2.7200000000000002)
> (1, 520, 3.1400000000000001, 2.7200000000000002)
> (1, 520, 3.1400000000000001, 2.7200000000000002)
> (1, 520, 3.1400000000000001, 2.7200000000000002)
> Traceback (most recent call last):
> File "bug.py", line 14, in text
> return "%4d: %5d %8.2f %8.2f" % self.value[0] # this fails
> AttributeError: sipThis
> Segmentation fault
> [packer at taco python]$
> --
>
> Of course, later, I realized that the (b)right way to do this
> is to write something like:
> def __init__(self, parent, value):
> QListViewItem.__init__(self, parent,
> "format0" % value[0], "format1" % value[1])
> self.value = value
>
> and not to redefine:
> def text(self, column)
>
> but why does line 14 crash after being executed successfully
> 7 times?
I've experienced the same error (except that I didn't get a Segmentation
fault) inside the "toggled()" method in a subclass of PushButton. There I
was testing for string equality. The following line solved my problem:
bugWorkaround = str(self.__dict__)
If you insert this before line 14 of this script you no longer get this error.
Any ideas?
-- Tad
More information about the PyQt
mailing list