Results 1 to 3 of 3

Thread: auto-disconnect in ~QGraphicsItem?

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default auto-disconnect in ~QGraphicsItem?

    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
    Qt Code:
    1. for (...)
    2. {
    3. scene->items().at(i).disconnect();
    4. }
    To copy to clipboard, switch view to plain text mode 

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

    Lykurg

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: auto-disconnect in ~QGraphicsItem?

    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.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: auto-disconnect in ~QGraphicsItem?

    Hi,

    here the related stuff of my virtual base class:
    Qt Code:
    1. class TextItemAbstract : public QObject, public QGraphicsItem
    2. {
    3. Q_OBJECT
    4. public:
    5. TextItemAbstract(QGraphicsItem *_parent = 0);
    6. virtual QRectF boundingRect() const = 0;
    7. virtual void paint(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget) = 0;
    8. signals:
    9. //...
    10. }
    11.  
    12. TextItemAbstract::TextItemAbstract( QGraphicsItem *_parent ) :
    13. QObject(), QGraphicsItem( _parent )
    14. {
    15. }
    To copy to clipboard, switch view to plain text mode 

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


    Thanks,

    Lykurg

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.