[Qt-interest] show a widget without a main window

Constantin Makshin dinosaur-rus at users.sourceforge.net
Thu Mar 5 20:32:48 CET 2009


Just create your top-level widget on the stack:

int main(int argc, char *argv[])
{
     QApplication app(argc, argv);
     myWidget w;
     w.show();
     return app.exec();
}

On Thu, 05 Mar 2009 11:19:10 +0300, Andreas Pakulat <apaku at gmx.de> wrote:
> On 05.03.09 07:13:03, Knowledge Seeker wrote:
>> Is not there a memory leak? there is no
>> delete w;
>> And also object 'w' is not linked to the parentobject - QApplication, so
>> it cant be automatically deleted !!
>
> Yes, but the leak exists only for a very short timeframe usually as its
> most of the time the last widget you close and when that happens the
> app.exec() call returns and main() is exited. At that point the
> operating system will re-claim all memory used by the application. So
> the leak only exists between closing the widget and exiting the
> application, which is usually acceptable, especially for demo apps.
>
> Of course this is different if that initial widget creates other
> top-level widgets and you then close the initial widget. In that case it
> should delete itself when its closed, or should be deleted from
> somewhere else.
>
> Andreas

-- 
Constantin "Dinosaur" Makshin



More information about the Qt-interest-old mailing list