Results 1 to 12 of 12

Thread: How do I read shared memory data written by Qt using boost ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: How do I read shared memory data written by Qt using boost ?

    On my Linux system QSharedMemory creates a file with the path given by key(). The generated key will be in /tmp. So for setKey("FOO") I get file "/tmp/qipc_sharedmemory_FOOfeab40e1fca77c7360ccca1481bb8 ba5f919ce3a" (a predictable name). If you use setNativeKey() you can explicitly direct the file name and location.

    On the same system Boost will look for the specified shared memory block name under /dev/shm. So,
    Qt Code:
    1. shared_memory_object shdmem(open_only, "FOO", boost::interprocess::read_only);
    To copy to clipboard, switch view to plain text mode 
    looks for, and fails to find, "/dev/shm/FOO"

    I expect that is what is going on with you. However, we are not privy to the behaviours and limits of Boost in your Cygwin environment.

  2. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How do I read shared memory data written by Qt using boost ?

    Now in addition to that, I created a shared memory using Boost shared memory in Qt, wrote a string into that. Then tried to access the same using another Boost program compiled in Cygwin-g++. Here get_size() is giving 0 and string is not being read. But surprising thing is, if I delete the same shared memory (for the specified key) using remove statement in cygwin-g++ program, it's getting deleted.

    Qt Code:
    1. bool isRemoved = boost::interprocess::shared_memory_object::remove("ShrdMem");
    2. std::cout << "Value = " << isRemoved << std::endl; // Value = 1
    To copy to clipboard, switch view to plain text mode 

    Writing in Qt(using QSharedMemory), then reading using Boost shared memory - Not working as expected
    Writing in Qt(using boost shared memory), then reading using Boost shared memory - Not working as expected
    Writing in Boost, reading in Boost(both compiled & run in cygwin-g++) - Working fine (tested to read the string/int value).

    Any help pls. Thank you.
    Last edited by rawfool; 16th May 2013 at 08:08.

  3. #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: How do I read shared memory data written by Qt using boost ?

    Writing in Qt(using boost shared memory), then reading using Boost shared memory - Not working as expected
    Writing in Boost, reading in Boost(both compiled & run in cygwin-g++) - Working fine (tested to read the string/int value).
    These are identical options. You don't write "in Qt(using boost shared memory)"... Qt is not a programming language. You write in C++, just like the other option.

    I am assuming that your Qt application is not built in the Cygwin environment, i.e. it is native Windows, and that the shared memory environment that Cygwin gives its applications does not use Windows shared memory mechanisms. Consequently they do not meet in the middle.

    Why are you using Cygwin anyway?

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

    rawfool (17th May 2013)

  5. #4
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How do I read shared memory data written by Qt using boost ?

    I'm developing a GUI application, which needs communication with other process(built using Visual C++). I'm developing my app in Qt and trying to emulate the other process shared memory using boost, so just thought to do it Cygwin, thinking shared memory can be accessed commonly which requires a key and the key is unique.

    The objective is to set-up a shared memory communication between two processes (one developed using Qt & other using Visual C++.
    I'm trying to get one of the below mentioned two options to workout -
    1. Using QSharedMemory from my side(GUI) and interacting with other process which is using Boost.
    2. Using Boost interprocess in Qt since the other process too is using Boost.

    Thank you.
    Last edited by rawfool; 16th May 2013 at 11:00.

  6. #5
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How do I read shared memory data written by Qt using boost ?

    I solved the issue.

    As ChrisW67 mentioned, the problem is in meeting point. May be the Cygwin-g++ program was looking in other folder (may be /tmp/ as mentioned above by @ChrisW67).
    I created a Non-Qt C++ program, using Qt creator and read the shared memory using Boost ipc. It worked fine, I was able to read the string that I wrote in Qt program(Boost Shared memory).

    Thank you ChrisW67 & anda_skoa
    Last edited by rawfool; 17th May 2013 at 11:25.

  7. The following user says thank you to rawfool for this useful post:


Similar Threads

  1. How to read value which written inside the QLineEdit
    By RENOLD in forum Qt Programming
    Replies: 4
    Last Post: 16th February 2012, 13:59
  2. shared memory - the right way to do it
    By fearu in forum Newbie
    Replies: 0
    Last Post: 26th October 2011, 23:46
  3. Replies: 1
    Last Post: 18th October 2010, 16:07
  4. QPixmap: X11 "memory leak" due to shared pixmap data?
    By chezifresh in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2009, 19:53
  5. QT shared memory
    By sweetsubha2020 in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2009, 05:30

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
  •  
Qt is a trademark of The Qt Company.