Results 1 to 3 of 3

Thread: Transfer Huge JSON Data from Asynchronous Database Problem

  1. #1
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Transfer Huge JSON Data from Asynchronous Database Problem

    I was created server side program using for query database and then return result in JSON format to another client who connected to server.
    This program using for lot's of people access to this database and data will be update every second.
    Then I got problems about the data that return from server side it's not completed JSON data. It's has error occure when parsing JSON data.
    I'm a new on TCP/IP qt programming. Why the variable baRecv are different when it's display on Debug mode and UI mode?
    How can I solve this problem? and Is Asynchronous Database suitable for this situation?

    Thanks for any help.
    Attached Files Attached Files

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

    Default Re: Transfer Huge JSON Data from Asynchronous Database Problem

    You assume that non-trivial data sent in one write() is received in one block. This is rarely the case. For example at mainwindow.cpp line 47 you assume you have 10 bytes to read as a byte count in text format; you may not have 10 bytes here. Then you assume the remaining bytes are a complete payload, you may have no bytes, part of the byte count plus payload, all of a payload, or even all of a payload plus the start of another transmission (I didn't look at your server).

    You need to buffer data in response to readyRead() signals until you know you have a complete protocol data unit and then decode it.

  3. #3
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Transfer Huge JSON Data from Asynchronous Database Problem

    I cut out 10 bytes in text format from my code.
    Use global variable to buffer response data and join it together.
    Then use some phase of my protocol to check end of protocol.
    Everything is OK in my client side.

    Is in server side has the best way to return data from query thread?

Similar Threads

  1. Asynchronous loading from HTTP (as data stream)
    By shestero in forum Qt Programming
    Replies: 0
    Last Post: 21st October 2012, 10:45
  2. model/view json data displaying
    By binaural in forum Qt Programming
    Replies: 5
    Last Post: 27th June 2012, 08:13
  3. How to store huge data in a Qt software
    By Momergil in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2012, 22:43
  4. Sort huge data use QSortFilterProxyModel
    By jiaorenjie in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2011, 02:56
  5. Problem while inserting the data into database
    By sudheer168 in forum Qt Programming
    Replies: 2
    Last Post: 13th December 2008, 12:22

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.