[Qt-interest] Memory Management in Qt

Daniel Price daniel.price at fxhome.com
Thu Oct 28 13:08:40 CEST 2010


> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Oliver.Knoll at comit.ch
> Sent: 26 October 2010 09:34
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Memory Management in Qt
>

> So normally a user calls "Open file" several times, and each time a QFileDialog would be instantiated - and never deleted, until the application quits.

See Qt::WA_DeleteOnClose.

> I agree, this example is somewhat artificial (normally you would
> instantiate a QFileDialog on the stack, and not on the heap, so problem
> solved :).

I hope not. This is now considered bad practice. You should create the dialog on the heap and connect to the signals it emits. You should not assume that the parent window out-lives the dialog! It is very easy to crash most Qt applications (at least on X11) by killing the main window while a model dialog is shown. Same thing for contextual menus. See

http://labs.qt.nokia.com/2010/02/23/unpredictable-exec/




This email is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. Errors and Omissions Excluded. If you are not the intended recipient please notify the sender. Please delete the message from all places in your computer where it is stored. You should not copy the email or use it for any purpose or disclose its contents to any other person. To do so may be unlawful. Email is an informal means of communicating and may be subject to data corruption accidentally or deliberately. For this reason it is inappropriate to rely on advice contained in an email without obtaining written confirmation of it first.

FXhome Limited is a limited company registered in England and Wales. Registered number: 04172812. Registered office: The Henderson Business Centre, Ivy Road, Norwich, Norfolk, NR5 8BF, U.K.




More information about the Qt-interest-old mailing list