[PyQt] How to read/write in QSharedMemory

Phil Thompson phil at riverbankcomputing.com
Wed Jul 29 09:53:39 BST 2009


On Wed, 29 Jul 2009 10:30:24 +0200, TGS France Alexandre
<alexandre.raczynski at technogerma.fr> wrote:
> Hi,
> 
> It looks like there is nothing available in PyQt to read from a 
> QSharedMemory or to write into it.
> How to use the sip.voidptr returned by QSharedMemory.data()?

http://www.riverbankcomputing.com/static/Docs/sip4/python_api.html#sip.voidptr

> Here is a piece of code that shows the writing problem:
> 
> /# Encode data into a buffer/
> buffer = QtCore.QBuffer()
> buffer.open(QtCore.QIODevice.WriteOnly)
> out = QtCore.QDataStream(buffer)
> out.writeInt32(1234)
> size = buffer.size()
> 
> /# Create the shared memory/
> sharedMemory = QtCore.QSharedMemory('key')
> sharedMemory.create(size)
> 
> /# Write the encoded data into the shared memory/
> sharedMemory.lock()
> *memcpy(sharedMemory.data(), buffer.data().data(), size)* # How to do 
> somehting like that?
> sharedMemory.unlock()

So...

mutable_data = buffer(sharedMemory.data())

...should give you write access to the memory.

Phil


More information about the PyQt mailing list