Results 1 to 3 of 3

Thread: QDataStream and QSql Object. Urgent!! please

  1. #1
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QDataStream and QSql Object. Urgent!! please

    Hi!

    I need to pack and unpack a QSqlQuery or a QSqlResult into a QByteArray and using a QDataStream. I need this because later I am supposed to send/received the QByteArray through a tcp socket.

    To pack the QSqlQuery I used the result() function:

    Qt Code:
    1. QByteArray dataBlock;
    2. QDataStream dataStream(&dataBlock, QIODevice::WriteOnly);
    3.  
    4. dataStream << sqlQuery.result();
    5.  
    6. return dataBlock;
    To copy to clipboard, switch view to plain text mode 

    now when I try to do the opposite I get errors, QDataStream:perator :

    Qt Code:
    1. QSqlResult *result;
    2. QDataStream dataStream(&qba, QIODevice::ReadOnly);
    3.  
    4. dataStream >> result; //error
    5.  
    6. _query = QSqlQuery(result);
    To copy to clipboard, switch view to plain text mode 

    is there a solution or even a better way to do this?

    thanks
    Last edited by ruben.rodrigues; 15th August 2011 at 12:42.

  2. #2
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDataStream and QSql Object. Urgent!! please

    Have you checked what data is transferred ? I would be surprised if the actual SQL result is in there.

    Anyway, since QSqlResult is an abstract interface class, you cannot use >> onto it I think.

    See the documentation of QDataStream : "For any (other) Qt class you wnat to use with QDataStream, you have to provide the >> and << operators".

    Regards,
    Marc

  3. The following user says thank you to marcvanriet for this useful post:

    ruben.rodrigues (16th August 2011)

  4. #3
    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: QDataStream and QSql Object. Urgent!! please

    Stream the row and column count, then iterate through the result set and serialise each row, column by column. You can stream the QVariant values as-is, or convert them to desired types first. At the moment you are serialising the pointer returned by QSqlQuery::result().

  5. The following user says thank you to ChrisW67 for this useful post:

    ruben.rodrigues (16th August 2011)

Similar Threads

  1. Using auto_increment in QSql
    By SykeS in forum Newbie
    Replies: 3
    Last Post: 21st May 2010, 07:13
  2. QSql Database
    By addu in forum Qt Programming
    Replies: 6
    Last Post: 20th July 2009, 13:37
  3. Replies: 8
    Last Post: 27th August 2007, 15:45
  4. QSql error
    By renjithmamman in forum Qt Programming
    Replies: 4
    Last Post: 20th December 2006, 10:28
  5. Cannot use QSql drivers
    By xgoan in forum Newbie
    Replies: 2
    Last Post: 25th August 2006, 15:45

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.