PDA

View Full Version : about the QSharedMemory



banban0802
25th July 2010, 14:55
Hi,all!
I got a question about class QSharedMemory.
If I apply a shared memory using QSharedMemory,can I get its content by Windows API(such as CreateFileMapping)?
Someone says some changes have to be made to the shared memory key,is it true?
Can you give me some examples?

tbscope
25th July 2010, 15:07
I guess you want to use the key as the name of the file mapping?

If so, you need to convert the QString into a TCHAR array.
This link might have useful information:
http://lists.trolltech.com/qt-interest/2005-10/thread00134-0.html

banban0802
26th July 2010, 01:50
To be exactly,I write a interface by Qt4 for my program,but the program is without Qt.
I hope this two processes communicate by shared memory,can this make it ?
thank you !

daemonna
4th August 2010, 07:18
if you use qsharedmemory in your program, they cannot communicate

Warning: QSharedMemory changes the key in a Qt-specific way. It is therefore currently not possible to use the shared memory of non-Qt applications with QSharedMemory.

but if you use only QT UI and shared memory with shmemget/set or similar non-QT way, than it's ok.

fre
10th August 2010, 11:55
Does anyone have any idea why they did this name mangling? With QtSharedMemory in Qt Solutions, which is the last version of it I've used, it was pretty easy to reproduce the algorithm for generating the key in other languages. But there must be some good reason for why this shouldn't be done...

fre
10th August 2010, 12:08
Found this myself after some Googling:
http://qt.gitorious.org/qt/qt/merge_requests/1497

I guess the short answer is that they need to perform the mangling due to naming restrictions on the underlying platform, and that we will have some new functions in 4.8 to work directly with native keys..