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

Roland Hughes roland at logikalsolutions.com
Sat May 19 00:14:04 CEST 2018



On 05/18/2018 04:57 PM, alexander golks wrote:
> the QFile::write call returns with no error, i called GetLastError() after the QFile::write() and got 183.
> the file is written up to ~30MB, and suddenly already exists?
> i am pretty sure, the file doesn't exist prior the call.

First: are you running under an account or on a system with file quotas? 
Bizarre errors can happen when you exceed quota.

Second: You haven't inadvertently linked in some error handling code 
which is:
    a) trying to look up error text in a file you don't have installed
    b) trying to log an error to a file in a path which does not exist
You have to be really good at debugging to identify this. It involves 
being able to set a Watch on the memory location storing the error so 
you can get traceback information from the call stack.

Third: Are you writing to an SD or MicroSD card?
   There are significant throughput limitations on such devices. 
Normally, when you exceed such throughput, like a JSON file which you 
are attempting to store then reload to change a value, if the reload 
request happens before the physical write completes the device gets 
placed into read-only mode.

Fourth: Throttle your I/O.
   Thread off the file I/O and have the thread sleep one second between 
physical writes. If you are trying to spew a 30+Meg chunk on a wanna-be 
processor from inside of the main event loop you've have already created 
problems for yourself and your application.

The fourth approach is the easiest for you to do. Have the thread buffer 
write requests and perform them 1 second apart. If your problem 
magically goes away, the problem is not "technically" in your code. Run 
additional tests decreasing the sleep time until the problem occurs 
again and you have to look into the Second thing I mentioned. My gut 
tells me your problem is in the Second situation. There really is a 
missing file some error handling text is looking for and you don't have. 
This second problem is masking what the real problem is.

You can get "some" inkling about the problem by tailing syslog. On 
Debian based system that is opening a terminal and typing

roland at roland-I5-HP-Compaq-8300-Elite-SFF-PC:~$ tail -f /var/log/syslog

before starting your application. If something in the OS is throwing an 
error you "should" see an entry popup in the display.

Keep in mind your "file does not exist" error can be popping up from a 
completely different logic path. I'm not 100% certain, but, I believe 
"file does not exist" can be set by something as innocent as calling 
tr() without a defined translation file. That means the error causing 
your other issue does not set errno. The value in errno is the LAST 
ERROR WHICH HAPPENED IN THE THREAD, which may or may not have anything 
to do with your problem.

Even if you do not explicitly code tr() or some other translation 
method, if you used the designer the generated code could have added 
translation logic for any displayed text. Given the way the event loop 
operates, you cannot be certain what got executed in what order.


-- 
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/20180518/3fafcbc0/attachment.html>


More information about the Interest mailing list