Results 1 to 2 of 2

Thread: QByteArray in Qt3

  1. #1
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default QByteArray in Qt3

    Hello All,
    I have a code snippet written in Qt4. I want to port the following code to Qt3. I have given my attempt but the data what I get is "not complete". Since the data is binary, I assume a NULL character is encountered and terminates to read further.

    Qt4 code

    Qt Code:
    1. QFile fRead(inputFileName);
    2. if (!fRead.open(QIODevice::ReadOnly))
    3. return;
    4.  
    5. QByteArray message = fRead.readAll();
    6. fRead.close();
    7.  
    8. QByteArray left16 = message.left( 16 ); //get first 16 bytes
    9. QByteArray restRightAfter16 = message.right( message.length() - 16 );
    To copy to clipboard, switch view to plain text mode 

    Qt3 code

    Qt Code:
    1. QFile fRead(inputFileName);
    2. if (!fRead.open(IO_ReadOnly))
    3. return;
    4.  
    5. QByteArray message = fRead.readAll();
    6. fRead.close();
    7.  
    8. QCString strleft16 = QCString( message.data() );
    9. QByteArray left16 = strSalt.left( 16 );
    10.  
    11. QCString strRestRightAfter16 = QCString( message.data() );
    12. QByteArray restRightAfter16 = strRestRightAfter16.right( strBody.length() - 16 ); //I dont the full data into restRightAfter16. The data is incomplete.
    To copy to clipboard, switch view to plain text mode 

    The binary file is really large and I want to read the entire data as given in the code above. I dont have any problems with Qt4 code and it works very fine.
    Where I'm I going wrong?

    Thanks
    Last edited by joseph; 5th September 2007 at 11:39.

  2. #2
    Join Date
    Sep 2007
    Location
    Finland
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray in Qt3

    Use QDataStream class.

    Qt Code:
    1. The QDataStream class provides serialization of binary data to a QIODevice.
    To copy to clipboard, switch view to plain text mode 

    Example from Qt3 docs:

    Qt Code:
    1. QFile file( "file.dat" );
    2. file.open( IO_ReadOnly );
    3. QDataStream stream( &file ); // read the data serialized from the file
    4. QString str;
    5. Q_INT32 a;
    6. stream >> str >> a; // extract "the answer is" and 42
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QByteArray format
    By nowire75 in forum Newbie
    Replies: 1
    Last Post: 13th July 2007, 09:53
  2. QByteArray with network data
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2007, 17:53
  3. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 17:01
  4. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:23
  5. How to read a Number from the QByteArray
    By antonio.r.tome in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2006, 15:24

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.