Results 1 to 17 of 17

Thread: problem with memcpy

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: problem with memcpy

    Quote Originally Posted by tbscope View Post
    First:

    Qt Code:
    1. void *
    To copy to clipboard, switch view to plain text mode 
    Is not a character array.

    A question. What is the ultimate goal to put an object into a "character array"? What are you trying to achieve?
    Please also define character array. Is this like a string?
    Well tbscope, leave that example which i gave there. Actually, the thing is that i have a structure and some fields in it. So, now i need to copy all the contents of the structure to any array (may be QByteArray or Character array). But well, i have not been able to do it upto now. Leave the problem of memcpy, because that's not working. Can you suggest any other way of doing this copy?

    With regards,

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with memcpy

    Quote Originally Posted by sattu View Post
    Can you suggest any other way of doing this copy?
    If you don't care about the ultimate size of the serialization, use QDataStream. If you do care then use QDataStream and then compress the resulting array using qCompress(). You'll get a byte array that you can send via a network link and then reverse the operation to receive the original structure.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    sattu (28th September 2010)

  4. #3
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: problem with memcpy

    Quote Originally Posted by wysota View Post
    If you don't care about the ultimate size of the serialization, use QDataStream. If you do care then use QDataStream and then compress the resulting array using qCompress(). You'll get a byte array that you can send via a network link and then reverse the operation to receive the original structure.
    O.k, fine. Actually my friend is trying with QDataStream, but is getting so many errors, due to lack of proper knowledge of exact syntax. Let me try more with it, and see what i get.

  5. #4
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: problem with memcpy

    Quote Originally Posted by wysota View Post
    If you don't care about the ultimate size of the serialization, use QDataStream. If you do care then use QDataStream and then compress the resulting array using qCompress(). You'll get a byte array that you can send via a network link and then reverse the operation to receive the original structure.
    Hi wysota!
    can you suggest me some qt examples where they have used the concept of QDataStream to serialize the required datas and then store it in a qbytearray?
    Because i'm not able to get the basic idea regarding the it's use, so an example would do much better. So, can you just send me some useful examples?

  6. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with memcpy

    You should overload << operator and let the structure serialise itself. That way if you use different compiler/architecture, you don't have to worry about how the structure is formed in memory.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with memcpy

    There is an example in QDataStream docs. It's using QFile as the carrier but you can also pass it a byte array pointer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    sattu (29th September 2010)

Similar Threads

  1. Replies: 11
    Last Post: 3rd April 2012, 04:51
  2. Save 4 Integers in a QByteArray without memcpy
    By GonzoFist in forum Newbie
    Replies: 3
    Last Post: 17th May 2010, 23:15

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.