[Qt-interest] qfile and qtextstream oddities
Aharon Campos
aharoncampos at gmail.com
Tue Jan 6 23:33:25 CET 2009
> On Tuesday 06 January 2009 22:57:26 Mike A. Delaney wrote:
>
>> I am trying to create a class that has a QFile and QTextStream member
>> but I noticed that even though the QFile reports the file is open and
>> writable anything I try to send to the QTextStream never shows up in the
>> file; the file size remains zero. However, if I create a function and
>> try to use the same open parameters and same method calls the text file
>> is populated with the expected results.
>> Can anyone help me figure out what I'm doing wrong?
>>
>
> Without looking at the example: You do know that Qt caches your data? So
> unless you write a lot of data (and fill Qt's buffer) it will only show on disk
> when you call flush() or finish writing and close the file.
>
> Maybe that already answers your question...
>
> Arnold
>
>
True, if you don't call close() on the QFile object, changes you've made
won't be reflected on the file.
I just want to point out that QFile's destructor calls close() if
necessary, and that's probably why you can see the changes when you
write to a file with a function call (if you create the QFile object on
the stack, inside your function, it's destroyed when exiting the
function's scope).
If you're using pointers, you need to delete them or call close() yourself.
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090106/df3578c2/attachment.html
More information about the Qt-interest-old
mailing list