Results 1 to 5 of 5

Thread: Question about "delete" on QMenuBar instance..

  1. #1
    Join Date
    Jan 2009
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Question about "delete" on QMenuBar instance..

    Suppose I create a QMenuBar using "new" in c++, then I create a QMenu using "new".. I then use addMenu to add the qmenu to the qmenubar.. Then I go and "delete" the qmenubar instance.. Is the memory allocated to qmenu freed up then?

    In my program did this above and then deleted the qmenubar and then when I tried to delete the qmenu instance, my program blew up.. But if I deleted the qmenu instance and then the qmenubar instance, everything worked fine..

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Question about "delete" on QMenuBar instance..

    In Qt parent objects are deleteing their children. So if your QMenu object was a child of the QMenuBar, then deleting QMenuBar also deletes QMenu - so then you tried to delete QMenu again so the app crashed.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Jan 2009
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about "delete" on QMenuBar instance..

    Understood..

    Suppose you have a qaction with its "triggered" signal attached to a slot.. The qactions parent is a qmenu, the qmenus parent is a qmenubar.. If you delete the qmenubar, does the slot-signal attachment for the qaction go away or do you need to disconnect it before you delete qaction or its parent?

  4. #4
    Join Date
    May 2008
    Posts
    155
    Thanked 15 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Question about "delete" on QMenuBar instance..

    Quote Originally Posted by tgreaves View Post
    Understood..

    Suppose you have a qaction with its "triggered" signal attached to a slot.. The qactions parent is a qmenu, the qmenus parent is a qmenubar.. If you delete the qmenubar, does the slot-signal attachment for the qaction go away or do you need to disconnect it before you delete qaction or its parent?
    You do not have to disconnect, the connection will be deleted automatically
    properly.

  5. The following user says thank you to ktk for this useful post:

    johnmauer (19th January 2010)

  6. #5
    Join Date
    Jan 2009
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about "delete" on QMenuBar instance..

    Awesome.. Thanks for your help guys..

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.