Results 1 to 3 of 3

Thread: delete QtObject

  1. #1
    Join Date
    Mar 2009
    Posts
    28
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default delete QtObject

    hi, last time i ask you about create several QPushButtons and connect these buttons with slots. Today want ask you to delete these buttons.

    I create buttons and store their pointer to struct like: createdB[i] = new QPushButton;
    When i destroy button i call: delete createdB[i]; it is OK, but ..

    when a create for example a QMenu for QPushButton: QPushButton->setMenu(new QMenu); or insert same widget: QPushButton->layout->addWidget(..);

    is it corect when i call only: delete createdB[i]; or i MUST call "delete" for everything what is create for button: delete QPushButton->layout...; delete QPushButton->menu..; and finally: delete createdB[i];

    i'am not sure about this. thanks.

  2. #2
    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: delete QtObject

    If your button is parent to all the stuff inside (I just wonder why your button has a layout you access...) then it is absolutely right only to delete the button. Qt will delete all children itself.
    You might want use QObject::deleteLater().

  3. #3
    Join Date
    Mar 2009
    Posts
    28
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: delete QtObject

    The layout button is for graphics..
    And thanks a lot.

Similar Threads

  1. new & delete usage.
    By SteveH in forum Newbie
    Replies: 2
    Last Post: 13th March 2009, 22:50
  2. Replies: 4
    Last Post: 19th February 2009, 11:10
  3. Best way for a graphicsitem to delete itself
    By pherthyl in forum Qt Programming
    Replies: 7
    Last Post: 22nd June 2008, 05:57
  4. Delete dialog
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 12:42
  5. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38

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.