Hi, On Friday 10 January 2014, 程梁 wrote: > Following is my example code: > > int main(int argc, char *argv[]) > { > QApplication app(argc, argv); > QLabel *label = new QLabel; > label->show(); > return app.exec(); > } > > label should live longer than app so there might be unsafe because any > QPaintDevice must have a QApplication. I'm not sure am I right? That's > all main widgets should create on stack in main() in order to avoid such > things? Or there is no such requirement?
In this particular case it should not present a problem because of the mechanism how app.exec() returns: when the last visible widget is closed the main event loop (i.e. app.exec()) exits and main ends (also killing the app object). Meaning: all widgets are already invisible. Otherwise, if it is killed with qApp->close(), the last action that QApplication takes is to unmap (close) all windows. Of course the code would be cleaner if you told the QLabel to kill itself on closure: label->setAttribute(Qt::WA_DeleteOnClose); Konrad
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest