Results 1 to 4 of 4

Thread: how to read a file that greater than 4G?

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default how to read a file that greater than 4G?

    How to read a file that is greater than 4G with Qt?

    thank you.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: how to read a file that greater than 4G?

    The same way you do a smaller file. You just need to use long long integers more carefully.
    Qt Code:
    1. #include <QtCore>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QCoreApplication app(argc, argv);
    7.  
    8. QFile file("test.dat");
    9. qDebug() << file.size();
    10. if (file.open(QIODevice::ReadOnly)) {
    11. bool ok = file.seek( 4097 * 1024 * 1024LL );
    12. qDebug() << ok;
    13. QByteArray data = file.read(1024);
    14. qDebug() << data.size();
    15. file.close();
    16. }
    17. return 0;
    18. }
    To copy to clipboard, switch view to plain text mode 
    output for my test file:
    Qt Code:
    1. 4299161600
    2. true
    3. 1024
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to read a file that greater than 4G?

    thank you.
    I know that in C++/C,the seek function has a start mode(current ,begin,or end),but the seek method of QFile has no the parameter,where does it begin from where the position move forward?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: how to read a file that greater than 4G?

    In a random-access file it seeks to the specified byte starting from the front of the file, just like fseek() with SEEK_SET. Combine it with QFile::pos() and QFile::size() to get other behaviours.

Similar Threads

  1. Read contents from the file using QHTTP Read()?
    By Gokulnathvc in forum Newbie
    Replies: 2
    Last Post: 21st June 2011, 09:03
  2. Text width greater than the QRect
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2011, 09:27
  3. timer callback greater than 2 power 31
    By sriky27 in forum Qt Programming
    Replies: 4
    Last Post: 18th March 2009, 11:57
  4. is qt phonon can read realmedia file and divx file
    By fayssalqt in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2009, 16:42
  5. RGB values greater than 8bit & QColor?
    By smacchia in forum Newbie
    Replies: 11
    Last Post: 21st March 2007, 15:40

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
  •  
Qt is a trademark of The Qt Company.