Results 1 to 4 of 4

Thread: Help me to use QtSharedMemory to share the data objects

  1. #1
    Join Date
    Jan 2006
    Posts
    29
    Qt products
    Qt4
    Platforms
    Windows

    Default Help me to use QtSharedMemory to share the data objects

    Hi,

    I have some data objects need to be shared between 2 processes. I downloaded QtSharedMemory from Trolltech but I don't know how to use it to share my data objects.
    Could you show me some ideas to do that?

    Thanks very much!

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

    Default Re: Help me to use QtSharedMemory to share the data objects

    Didn't you get some example code with the package? Here is one: http://doc.trolltech.com/solutions/4...sscounter.html

  3. #3
    Join Date
    Jan 2006
    Posts
    29
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help me to use QtSharedMemory to share the data objects

    Thanks for replying!

    I think my problem is design.
    For instance, I have 2 processes A and B. I defined a class as following:
    class Foo
    {
    ...
    QString m_strData;
    int m_iData;
    }
    and I want to share a object of this class between 2 processes. Is there any way to put that object into the shared memory? Could you give me some example codes?

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

    Default Re: Help me to use QtSharedMemory to share the data objects

    Quote Originally Posted by gtthang
    and I want to share a object of this class between 2 processes. Is there any way to put that object into the shared memory? Could you give me some example codes?
    It is not advised to put objects into shared memory. Especially ones, which contain pointers (like QString), because the pointer will be invalid in the other process' address space. Instead use plain types or serialize objects you want to share. So you can use ints, arrays, etc. Using QDataStream for serialization and deserialization can be useful for more complex objects. For simple ones, store them directly. And treat the shared memory as an array of bytes and not as a general storage place, where you can put anything.

Similar Threads

  1. Sharing data between objects
    By Mr_Grieves in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2009, 00:13
  2. What is the best way to share data between 2 programs?
    By ModeZt in forum Qt Programming
    Replies: 2
    Last Post: 27th May 2008, 21:23
  3. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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.