On Fri, 16 Jan 2015 15:25:44 +0300, Bo Thorsen <[email protected]> wrote:
> Den 16-01-2015 kl. 13:01 skrev Igor Mironchik: >> Hi. >> >> On Fri, 16 Jan 2015 14:44:08 +0300, Koehne Kai >> <[email protected]> wrote: >> >>> >>>> -----Original Message----- >>>> From: [email protected] >>>> [mailto:[email protected]] >>>> On Behalf Of Igor Mironchik >>>> Sent: Friday, January 16, 2015 12:24 PM >>>> To: [email protected] >>>> Subject: [Interest] QTextStream doesn't write to QFile >>>> >>>> Hi. I'm doing a simple log class. I'm sure that Log creates after >>>> QCoreApplication. >>>> QCoreApplication is static. I create QCoreApplication as: >>>> >>>> static QSharedPointer< QCoreApplication > application( >>>> int argc = 0, char ** argv = 0 ) >>>> { >>>> static QSharedPointer< QCoreApplication > app( >>>> new QCoreApplication( argc, argv ) ); >>>> >>>> return app; >>>> } >>> It seems you're desperately trying here to extend QCoreApplications >>> lifetime as long as possible. This is just asking for trouble: just let >>> QCoreApplication be destructed when your application exits, in >>> main.cpp. >> I'm not desperately trying to extens QCoreApplication lifetime. I need >> it >> for that reason that Log is singleton and uses QObjects. So Log have to >> be >> destructed before QCoreApplication. >> >> It's normal practice when using singletons in Qt apps. It works well in >> other my application. > > If you want to delete the singletons before the QApplication, call a > delete on them after exec() returns. The order of static deletes is > undefined. > > It does not work well in any application other than by pure chance. > > But why would you think that a QObject can't be deleted after > QApplication? That works fine, as long as you don't do something else in > the destructors that use any objects deleted by the QApplication. Few years ago in this list Nils Jeisecke wrote to me that QWidget's destructor needs QApplication instance. So I think that QObject's destructor needs QCoreApplication. > > One thing you can do to make certain objects are deleted before the qApp > is to make qApp the parent of the singletons. This also works if > QApplication is instantiated on the stack. Thank you for your suggestions. -- Best Regards, Igor Mironchik. _______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
