How to get number of bytes read from QTextStream

Posted by user261882 on Stack Overflow See other posts from Stack Overflow or by user261882
Published on 2010-06-08T13:58:13Z Indexed on 2010/06/08 14:02 UTC
Read the original article Hit count: 184

Filed under:
|
|
|

The following code I am using to find the number of read bytes from QFile. With some files it gives the correct file size, but with some files it gives me a value that is approximatively fileCSV.size()/2. I am sending two files that have same number of characters in it, but have different file sizes link text. Should i use some other objects for reading the QFile?

QFile fileCSV("someFile.txt");
if ( !fileCSV.open(QIODevice::ReadOnly | QIODevice::Text))
   emit errorOccurredReadingCSV(this);
QTextStream textStreamCSV( &fileCSV );        // use a text stream
int fileCSVSize = fileCSV.size());
qint64 reconstructedCSVFileSize = 0;
while ( !textStreamCSV.atEnd() )
{
     QString line = textStreamCSV.readLine();         // line of text excluding '\n'
     if (!line.isEmpty())
     {
         reconstructedCSVFileSize += line.size(); //this doesn't work always
         reconstructedCSVFileSize += 2;
      }
    else
       reconstructedCSVFileSize += 2;
}

I know that reading the size of QString is wrong, give me some other solutions if you can.

Thank you.

© Stack Overflow or respective owner

Related posts about c++

Related posts about qt