Results 1 to 6 of 6

Thread: Struct to QByteArray

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Struct to QByteArray

    Hello

    Based on this topic, I would like to know:

    Is there another reasonable way of converting a struct to a QByteArray that doesn't use QDataStream?

    Thanks,

    Momergil

    Edit: the only other way I'm aware now is:

    Qt Code:
    1. MyStruct structTemp;
    2.  
    3. //Fill structTemp
    4.  
    5. char buffTemp[sizeof(structTemp)];
    6.  
    7. memcpy(buffTemp, &structTemp, sizeof(structTemp));
    8.  
    9. QByteArray baTemp = QByteArray::fromRawData(buffTemp,sizeof(structTemp)));
    To copy to clipboard, switch view to plain text mode 
    Last edited by Momergil; 3rd July 2014 at 18:07.
    May the Lord be with you. Always.

Similar Threads

  1. QList<struct>
    By Axsis in forum Newbie
    Replies: 11
    Last Post: 12th October 2015, 07:48
  2. Replies: 6
    Last Post: 14th May 2014, 12:14
  3. Replies: 11
    Last Post: 3rd April 2012, 04:51
  4. Replies: 1
    Last Post: 22nd June 2011, 08:12
  5. Replies: 9
    Last Post: 25th July 2009, 13:27

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.