Results 1 to 3 of 3

Thread: How to get number of bytes read from QTextStream

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2008
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question How to get number of bytes read from QTextStream

    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 files..zip, but have different file sizes. Should i use some other objects for reading the QFile?

    Qt Code:
    1. QFile fileCSV("someFile.txt");
    2. if ( !fileCSV.open(QIODevice::ReadOnly | QIODevice::Text))
    3. emit errorOccurredReadingCSV(this);
    4. QTextStream textStreamCSV( &fileCSV ); // use a text stream
    5. int fileCSVSize = fileCSV.size());
    6. qint64 reconstructedCSVFileSize = 0;
    7. while ( !textStreamCSV.atEnd() )
    8. {
    9. QString line = textStreamCSV.readLine(); // line of text excluding '\n'
    10. if (!line.isEmpty())
    11. {
    12. reconstructedCSVFileSize += line.size(); //this doesn't work always
    13. reconstructedCSVFileSize += 2;
    14. }
    15. else
    16. reconstructedCSVFileSize += 2;
    17. }
    To copy to clipboard, switch view to plain text mode 

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

    Thank you.
    Last edited by slobo_n; 8th June 2010 at 14:44. Reason: updated contents

Similar Threads

  1. How to read only a certain amount of bytes
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 28th January 2009, 07:38
  2. Read/Write from QTextStream
    By tonde in forum Qt Programming
    Replies: 7
    Last Post: 31st July 2008, 16:51
  3. socket read/write bytes
    By nowire75 in forum Newbie
    Replies: 3
    Last Post: 4th July 2007, 23:12
  4. How to read more bytes using QTcpSocket?
    By vishesh in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2007, 20:23
  5. How to write bytes read from serial port to a QFile
    By shamik in forum Qt Programming
    Replies: 19
    Last Post: 25th June 2007, 14:12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.