[Qt-interest] Handle object deletions right with containers (not-working stripped example)

Wilhelm wilhelm.meier at fh-kl.de
Mon Aug 8 08:14:43 CEST 2011


Hi,

the attached example is motivated by working with QAbstractItemModel /
QProxyModel (writing a proxy model that can combine other models) but
not limited to.

In the example class Container holds pointers to objects, but does not
own(!) these objects. Any removal (and addition) of pointers results in
sending signals beginRemoveElement() / endRemoveElement() (as in
QAbstractItemModel).

The problem arises if one of the objects are deleted without removing it
first. I want to make this situation safe because the Container does not
own the objects. I use the QObject::destroyed() signal connected to slot
Container::elementDeleted(). But clearly this results in a crash calling
Container::remove().

So, how to handle this situation (bearing in mind that I'm looking for a
solution with QAbstractItemModel, where I have a similar situation
calling beginRemoveRows() / endRemoveRows())?

-- 
Wilhelm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: tester.h
Type: text/x-chdr
Size: 420 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110808/77259493/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tester.cc
Type: text/x-c++src
Size: 1141 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110808/77259493/attachment-0001.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cc
Type: text/x-c++src
Size: 519 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110808/77259493/attachment-0002.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: element.h
Type: text/x-chdr
Size: 243 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110808/77259493/attachment-0003.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: element.cc
Type: text/x-c++src
Size: 215 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110808/77259493/attachment-0004.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: container.h
Type: text/x-chdr
Size: 554 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110808/77259493/attachment-0005.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: container.cc
Type: text/x-c++src
Size: 1195 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110808/77259493/attachment-0006.bin 


More information about the Qt-interest-old mailing list