[Interest] QMacNativeWidget & memory management
deDietrich Gabriel
Gabriel.deDietrich at digia.com
Mon Dec 9 15:34:26 CET 2013
Hi Tim,
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
work:
i've adapted the example [1] 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.
Best regards,
Dr. Gabriel de Dietrich
Senior Software Developer
qt.digia.com<http://qt.digia.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131209/1e929e08/attachment.html>
More information about the Interest
mailing list