[Interest] QMacNativeWidget & memory management
Gabriel.deDietrich at digia.com
Mon Dec 9 15:34:26 CET 2013
On Dec 9, 2013, at 1:33 PM, Tim Blechmann <tim at klingt.org<mailto:tim at klingt.org>> wrote:
trying to embed a Qt widget hierarchy into a Cocoa hierarchy, i'm
currently trying to figure out how the memory management is supposed to
i've adapted the example  to add a RedWidget to the layout. it gets
allocated in the applicationDidFinishLaunching method, but for some
reason it is never destroyed. so i wonder, is this a bug or a feature?
or more generally speaking: will the QMacNativeWidget automatically be
destroyed when its parent NSView* is destroyed? if not, what is the
preferred way to make sure that it is destroyed correctly?
While the QMacNativeWidget’s underlying NSView will be destroyed by Cocoa when its parent view is, that NSView does NOT take ownership of any QWidget (Note that you should not cache the NSView pointer unless you’re sure about its lifespan. Furthermore, calling “QMacNativeWidget::nativeView()” will create a new NSView if it has already been deleted). Therefore, you should delete the QMacNativeWidget yourself. In the example, since we create the QMavNativeWidget in “applicationDidFinishLaunching:”, the right place to deallocate it would be “applicationWillTerminate:”. In this regard, the example is incomplete and should be fixed.
Dr. Gabriel de Dietrich
Senior Software Developer
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Interest