Results 1 to 13 of 13

Thread: Problem in converting Large QDomDocument to QByteArray

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #12
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem in converting Large QDomDocument to QByteArray

    Quote Originally Posted by sattu View Post
    Actually olive, using a delimiter isn't feasible as many times we need to transfer binary data. There is a possibility of the delimiter being present in the ACTUAL_DATA.
    You could use a hybrid protocol using length-prefixing for some messages and delimiters for others. Just prefix each message with a byte indicating which one of the two conventions is used for that message. This allows you to choose length-prefixing for binary data with predictable length, and delimiters for XML. This is not difficult to do, and may be the best approach in your situation.

    Quote Originally Posted by sattu View Post
    So, your first option looks the best but then again it's not possible to serialize the whole data before sending because there are chances of memory segmentation happening when no.of records are huge. So we are planning to add the following modifications to our protocol:-

    1) Reading from the database, forming the XML and then sending over the socket.....everything will happen frame by frame as told by you.
    2) Each frame will have the usual HEADER containing the length of ACTUAL_DATA present in that particular frame.
    3) Modification:- The first frame will have the additional info of the TOTAL NO.OF RECORDS that we would be send gradually. So at the receiver end we would keep looping until the no.of parsed records becomes equal to the value present in the HEADER of first frame.
    OK, that works too. Besides the receiving end can use the total number of records to optimize the allocation of the internal structures for storing the database.

    Quote Originally Posted by sattu View Post
    4) I am planning to skip the following step suggested by you. I hope this shouldn't be an issue:-
    Qt Code:
    1. streamWriter.writeStartDocument();
    2. streamWriter.writeEndDocument();
    3. Reason- I don't want the following header in my XML: <?xml version="1.0" encoding="UTF-8"?>
    To copy to clipboard, switch view to plain text mode 
    Is there a good reason for not including this small header? Frankly it does not weigh much compared to the huge database. The documentation for QXmlStreamWriter does not explicitly state that what you suggest is forbidden, but it does not state that it works as you expect either. I am more concerned about the receiving end. By removing this header (called the XML declaration), you remove the information about the text encoding. It seems that QXmlStreamReader relies on the XML declaration since it does not offer a way to set a codec manually. If I were you I would keep the XML declaration and save myself some trouble.

    Finally, if you can completely change the protocol, why do you use XML in the first place? You could encode the database to binary data. For example:
    Database = [number of records (integer)][record 1][record 2]...
    Record = [UserID (integer)][UserName (string)][UserTye (integer)]
    integer = big-endian 32-bit unsigned integer
    string = UTF-8 encoded string followed by NUL byte

    This format would also be suited to progressive serialization and deserialization.

  2. The following user says thank you to yeye_olive for this useful post:

    sattu (22nd August 2012)

Similar Threads

  1. Problem with QDomDocument
    By justin123 in forum Qt Programming
    Replies: 2
    Last Post: 18th March 2011, 07:40
  2. converting QByteArray to unsigned short
    By sattu in forum Qt Programming
    Replies: 16
    Last Post: 28th September 2010, 13:51
  3. QByteArray to new QDomDocument
    By cknoblock in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2009, 21:37
  4. QDomDocument problem !!!
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2006, 22:30
  5. Problem converting .ui files from Qt3 to 4
    By Amanda in forum Qt Programming
    Replies: 6
    Last Post: 28th October 2006, 04:34

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