[PyQt] QTextBlockUserData forgotten in SIP 4.14.3, bug?

Phil Thompson phil at riverbankcomputing.com
Sat Jun 8 18:24:58 BST 2013


On Sat, 8 Jun 2013 18:35:56 +0200, Olivier Keshavjee
<olivier.keshavjee at gmail.com> wrote:
> Hello,
> 
> I've seen that two months ago (
> http://www.riverbankcomputing.com/pipermail/pyqt/2013-March/032458.html)
a
> bug in PyQt caused QTextBlockUserData objects to be destroyed. This was
> announced to be fixed.
> 
> Yet I still experience the same behaviour. When using the following
syntax
> highlighter:
> 
> class DummyHighlighter(QSyntaxHighlighter):
>>
>>
>>  def __init__(self, parent):
>>
>> QSyntaxHighlighter.__init__(self, parent)
>>
>>
>>  def highlightBlock(self, text):
>>
>> data = self.currentBlockUserData()
>>
>> if not data: data = DummyTextBlockUserData()
>>
>> print(data.isValid()) # AttributeError here, see below
>>
>> self.setCurrentBlockUserData(data)
>>
>>
>>
>> class DummyTextBlockUserData(QTextBlockUserData):
>>
>>
>>  def __init__(self):
>>
>> QTextBlockUserData.__init__(self)
>>
>>
>>  def isValid(self):
>>
>> return True
>>
> 
> I get the following error:
> 
> Traceback (most recent call last):
>>     File "highlighter.py", line 20, in highlightBlock
>>         print(data.isValid())
>> AttributeError: 'QTextBlockUserData' object has no attribute 'isValid'
>>
> 
> This is using:
> 
>    - PyQt 4.10.1
>    - SIP 4.14.6
>    - Python 2.7.4
> 
> Is it still a bug?

Difficult to say without a short, complete example that demonstrates the
problem.

The user data is correctly owned by the QTextDocument that the highlighter
is operating on. However there may not be a reference to the document in
your application - particularly if you created the highlighter by passing a
QTextEdit to its ctor.

I'll make a change in tonight's snapshot to address that.

Phil


More information about the PyQt mailing list