PDA

View Full Version : auto-disconnect in ~QGraphicsItem?



Lykurg
21st July 2008, 10:51
Hi,

I have a lot of subclassed QGraphicsItems in a scene. Each of them is connected to slot x() of a class which handles the scene and the view. So when calling scene.clear(), all items will be destroyed, but will the connections also be disconnected or must I call this manually by
for (...)
{
scene->items().at(i).disconnect();
}

A brief look at the qt source hasn't made me clever... Thanks

Lykurg

jpn
21st July 2008, 11:28
QObject destructor does cleanup existing signal-slot connections. QGraphicsItem doesn't know anything about signal-slot connections. Plain QGraphicsItems cannot even have slots. You must've inherited QObject to be able to have signals and/or slots in a graphics item.

Lykurg
22nd July 2008, 08:14
Hi,

here the related stuff of my virtual base class:

class TextItemAbstract : public QObject, public QGraphicsItem
{
Q_OBJECT
public:
TextItemAbstract(QGraphicsItem *_parent = 0);
virtual QRectF boundingRect() const = 0;
virtual void paint(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget) = 0;
signals:
//...
}

TextItemAbstract::TextItemAbstract( QGraphicsItem *_parent ) :
QObject(), QGraphicsItem( _parent )
{
}

So even if I give QObject no parent after destroying TextItemAbstract the QObject does cleanup, or must I call ~QObject() explicit?


Thanks,

Lykurg