[Interest] Clarification re destructor in subclass of QWidget

Nikos Chantziaras realnc at gmail.com
Thu Aug 16 18:47:00 CEST 2012


The compiler will never create heap cleanup code for you.

Other than that, Qt objects that take a "parent" arg in their ctor are 
automatically deleted when the parent is deleted (by Qt, not by the 
compiler.)  So don't delete those manually in the dtor, unless you've 
set their parent to be NULL.


On 16/08/12 19:08, Shriramana Sharma wrote:
> Hello. I'm writing a program to interface with a drawing library and
> output its results to screen using Qt (you might have noticed my
> previous post with a minimal example of input/output/error tabs). Upon
> clicking a push button "Execute", the app will send the input field
> contents to the library and write its output and error messages into
> the respective fields. If it successfully processes the instructions,
> the drawing output by the library in SVG format to a separate stream
> will be drawn using a QSVGWidget on screen.
>
> Now the drawing library needs initiation before using it and cleanup
> while closing down the application. And since I have to connect the
> clicked() signal of the execute pushbutton to a executeCommands custom
> slot, I am subclassing MainWindow from QWidget, so I have included the
> library initiation into the constructor of MainWindow.
>
> My question: I am assuming that I have to include the library cleanup
> call in the destructor of MainWindow, but if I write a custom
> destructor, do I have to do any other delete calls to remove objects
> that are created on the heap in the constructor using new QTabWidget
> etc? If I don't have to call the library cleanup manually, could I
> simply leave out the destructor and the compiler will create the
> appropriate instructions itself?
>
> Thanks.
>





More information about the Interest mailing list