×

Discussion Board

Results 1 to 4 of 4

Thread: Reading files

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    Reading files

    Hi,

    im new in Qt, for my first program im trying to read a file, lets say, 6gb file and put it in a array (not all the data ofc) so i must read it 1024 in 1024 bytes.

    Some help would be appreciated.

    Regards.

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Reading files

    The most straight-forward approach is to use QIODevice::read (char *data, qint64 maxSize).

    Look at all the direct & inherited QFile members here:

    http://doc.qt.nokia.com/4.6-snapshot/qfile-members.html

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    Re: Reading files

    Quote Originally Posted by danhicksbyron View Post
    The most straight-forward approach is to use QIODevice::read (char *data, qint64 maxSize).

    Look at all the direct & inherited QFile members here:

    http://doc.qt.nokia.com/4.6-snapshot/qfile-members.html
    Thanks for the hint

    i solve the problem like this:

    Code:
    QFile rfile("myfile.dat");
    
    qint64 position = 0;
    qint64 readedbytes = 0;
    qint64 buffersize = 1024;
    char *data = new char [buffersize];
    
    if (rfile.open(QIODevice::ReadOnly))
    {
            while(1)
            {
                rfile.seek(position);
                readedbytes = rfile.read(data, buffersize);
                position += readedbytes;
                if(readedbytes == 0) break;
    
                QByteArray rfiledata(data, readedbytes);
            }
    }
    Regards

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Reading files

    Yeah, looks about right. Don't forget to delete the buffer when you're done.

    (Also, you might want to note that there is a QIODevice::read(qint64 maxSize) method that directly returns a QByteArray, though it doesn't give you an error indication other than to return an empty object.)

Similar Threads

  1. Maemo Repositorys Down?
    By beaua in forum Nokia N9
    Replies: 29
    Last Post: 2010-05-30, 16:20
  2. Reading XML files
    By NightStalkerDNS in forum Mobile Java General
    Replies: 1
    Last Post: 2009-12-24, 19:42
  3. Error loading connection when obfuscation high?
    By ejakkk in forum Mobile Java General
    Replies: 8
    Last Post: 2009-06-26, 12:54
  4. Reading files from MMC
    By igorcb in forum PC Suite API and PC Connectivity SDK
    Replies: 0
    Last Post: 2005-05-28, 00:23
  5. Reading Writing Files
    By marcgom in forum Mobile Java General
    Replies: 1
    Last Post: 2003-02-25, 08:11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×