PDA

View Full Version : Question about "delete" on QMenuBar instance..



tgreaves
30th March 2009, 21:22
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..

faldzip
30th March 2009, 21:54
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.

tgreaves
30th March 2009, 22:33
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?

ktk
30th March 2009, 22:45
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.

tgreaves
30th March 2009, 23:10
Awesome.. Thanks for your help guys..