[Qt-interest] Progress Bar Logic

Andre Somers andre at familiesomers.nl
Fri May 28 12:06:20 CEST 2010


On 28-5-2010 11:54, yogesh upreti wrote:
> Hallo Andre,
> Thanks for reply. I am using now reading and writing data with 16kb 
> buffer space.
> This is working good for my programme, however it is taking more time 
> than the normal copy.
Not much to do about that, I fear... Are you doing the read/write in a 
separate thread? That *may* help a *little*.
If you can find a system-level copy operation that returns progress 
information in a usable way, use that by any means.

> I have to use similier logic for reading txt files, but I am not 
> getting proper values. Here is what I do.
> 1. Calculate file size using QFile::size() function
> 2. Read file using QString line = QFile::readLine()  till 
>  line.isEmpty()  is not true
> 3. update the progress bar by line.size() value.
> But this process is getting my progress bar only till 90-95% 
> (depending on file size).
> Where do you think I am missing rest 5% of the file in this logic?
You are missing the linebreaks themselves, of course. :-) Depending on 
the format of the text files, this is one or two characters per line. 
Also, you may be running into encoding issues. If your text file is 
UTF-8 and contains some characters that require two or more bytes for 
example, those bytes will be reported by QFile::size, but you won't see 
each byte back as a character from QString::size().

Why not use QFile::pos() as the pointer where you are with reading your 
file? That will avoid both issues in one go...


André




More information about the Qt-interest-old mailing list