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

Roland Hughes roland at logikalsolutions.com
Thu May 17 17:31:55 CEST 2018



On 05/17/2018 09:11 AM, alexander golks wrote:
>> my code was:
>>    qint64 res = f.write(data);
> just for the curious ones:
>
> i have at least compiled 5.6.4 now, but i can not produce the error with my qt5core.
> using 5.6.3 from qt, error exists. using mine, does not exist...
>
> getting the error code directly after the f.write(data) gives me error code 183:
>    ERROR_ALREADY_EXISTS
>      183 (0xB7)
>      Cannot create a file when that file already exists.
>
> but i assume, that the error is not from the failing WriteFile call. or does it?
> anyone with some more ideas?
> e.g. on how to reproduce or test?

One of the annoying safety features of Qt is that it won't overwrite a 
file. You got that error when you tried to open the file for output and 
you didn't check for the error. There was some test case long ago where 
it was deemed a security risk for Qt to overwrite existing files. This 
deviates from standard C/C++ where you can. Before opening an output 
file you need to test for its existence then delete it. You can also 
play games with opening the file for I/O and truncating, but, success is 
file system dependent on that one.

-- 
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/20180517/044fbcb9/attachment.html>


More information about the Interest mailing list