[PyQt] Bug in QTableView.setModel()
apaku at gmx.de
Mon Jan 7 10:26:32 GMT 2008
On 07.01.08 11:12:10, Aaron Digulla wrote:
> Quoting Andreas Pakulat <apaku at gmx.de>:
>> On 06.01.08 21:13:44, Aaron Digulla wrote:
>>> The root cause is that setModel() doesn't increment the usage counter of
>>> the python class passed in, so Python will GC it if I don't save a
>>> pointer elsewhere.
>> Thats by purpose. One reason I can think of is that you often want to
>> use the model elsewhere to insert data or do something with the data and
>> then you often don't want a QAbstractItemModel instance but your
>> specific subclass.
> I'm talking about preventing the python class which is used as the model
> being garbage collected; it doesn't matter from which Qt class it is
> As it is, the class pointer is copied into the view class and then python
> frees the memory. That causes spurious display errors and crashes. No
> matter how you look at it, that's a bug.
No its not, the view doesn't take ownership of the model, neither in Qt
C++ nor in PyQt, thats why your object is garbage collected. A reason
for not taking ownership is that a model might be used in multiple
Troubled day for virgins over 16 who are beautiful and wealthy and live
in eucalyptus trees.
More information about the PyQt