[Interest] QTextStream doesn't write to QFile

Igor Mironchik igor.mironchik at gmail.com
Fri Jan 16 14:06:05 CET 2015


On Fri, 16 Jan 2015 15:25:44 +0300, Bo Thorsen <bo at vikingsoft.eu> wrote:

> Den 16-01-2015 kl. 13:01 skrev Igor Mironchik:
>> Hi.
>>
>> On Fri, 16 Jan 2015 14:44:08 +0300, Koehne Kai
>> <Kai.Koehne at theqtcompany.com> wrote:
>>
>>>
>>>> -----Original Message-----
>>>> From: interest-bounces+kai.koehne=theqtcompany.com at qt-project.org
>>>> [mailto:interest-bounces+kai.koehne=theqtcompany.com at qt-project.org]
>>>> On Behalf Of Igor Mironchik
>>>> Sent: Friday, January 16, 2015 12:24 PM
>>>> To: interest at qt-project.org
>>>> 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.



More information about the Interest mailing list