rawfool (17th May 2013)
Yeah, but I called the shared memory using the same key specified in the Qt program. I think that is the only way to access a shared memory. Is there anything that needs to be done ?
Thank you.
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,
looks for, and fails to find, "/dev/shm/FOO"Qt Code:
shared_memory_object shdmem(open_only, "FOO", boost::interprocess::read_only);To copy to clipboard, switch view to plain text mode
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.
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:
bool isRemoved = boost::interprocess::shared_memory_object::remove("ShrdMem"); std::cout << "Value = " << isRemoved << std::endl; // Value = 1To 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 09:08.
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.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).
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?
rawfool (17th May 2013)
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 12:00.
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 12:25.
Bookmarks