[Interest] QFile::write(const QByteArray&) does not write, all data?

Elvis Stansvik elvstone at gmail.com
Mon May 14 13:06:25 CEST 2018


2018-05-14 1:29 GMT+02:00 Thiago Macieira <thiago.macieira at intel.com>:
> On Sunday, 13 May 2018 09:32:23 PDT Elvis Stansvik wrote:
>> QDataStream can operate
>> fine on an QIODevice that does partial writes (like QFile).
>
> No, it cannot. If there's a failure to write, the stream is corrupt and
> unrecoverable.

Yes of course. I only meant that this is an corruption that the user
can check for (status() == QDataStream::WriteFailed), so QDataStream
works as intended (for some definition of "works").

But yes, my "operate fine" was an exaggeration and a little tounge in
cheek, sorry about that.

I still think that bit of advise to subclassers in the docs is a
little too demanding, how about instead:

When reimplementing this function it is important that this function
_tries to write_
  all the data available before returning. This is required in order
for QDataStream
  to be able to operate on the class. QDataStream assumes all the information
  was written and therefore does not retry writing if there was a problem.

The emphasis shows what I changed.

Because a device obviously can't write all data in some circumstances
(e.g. out of disk space).

I think it's the way it is written is what confused the OP and some
others, because it almost makes it sound as if all current subclasses
(like QFile) _will_ write all data (heed the advice in that
paragraph).

Elvis

>
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel Open Source Technology Center
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list