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

Roland Hughes roland at logikalsolutions.com
Mon May 14 18:17:42 CEST 2018



On 05/14/2018 10:54 AM, Richard Moore wrote:
> On Sat, 12 May 2018 at 15:45, Roland Hughes 
> <roland at logikalsolutions.com> wrote:
>> Any time a write comes up short, it is an error.
>>
> ?That is simply incorrect. It might not be how you would like it to behave,
> however it is the norm that short writes are allowed and should be handled
> by the callee. This is the case in POSIX, the C standard library etc. I'm
> afraid, you'll simply have to learn to live with it - an easy solution
> would be to write a tiny wrapper function of your own however if you do
> you'll need to be very careful with your error handling if you always want
> to be able to retry.
Your statement would be patently false.
=====
FREAD(3) Linux Programmer's Manual FREAD(3)

NAME
        fread, fwrite - binary stream input/output

SYNOPSIS
        #include <stdio.h>

        size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);

        size_t fwrite(const void *ptr, size_t size, size_t nmemb,
                      FILE *stream);

DESCRIPTION
        The function fread() reads nmemb items of data, each size bytes 
long, from the stream pointed to by stream, storing them at the location 
given by ptr.

        The function fwrite() writes nmemb items of data, each size 
bytes long, to the stream pointed to by stream, obtaining them from the 
location given by ptr.

        For nonlocking counterparts, see unlocked_stdio(3).

RETURN VALUE
        On  success,  fread()  and fwrite() return the number of items 
read or written.  This number equals the number of bytes transferred 
only when size is 1.  If an error occurs, or the end of the file is
        reached, the return value is a short item count (or zero).

        fread() does not distinguish between end-of-file and error, and 
callers must use feof(3) and ferror(3) to determine which occurred.

=====

Pay ___special___ attention to that last line, take straight from the 
man page of KDE linux.

The original poster's issue is that Qt is consuming the error. It is 
unreachable by the application so the application has no idea what to do.

-- 
Roland Hughes, President
Logikal Solutions
(630)-205-1593

http://www.theminimumyouneedtoknow.com
http://www.infiniteexposure.net
http://www.johnsmith-book.com
http://www.logikalblog.com
http://www.interestingauthors.com/blog
http://lesedi.us/
http://onedollarcontentstore.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180514/36b9a526/attachment.html>


More information about the Interest mailing list