[PyQt] Access to QSharedMemory with buffer protocol

Hans-Peter Jansen hpj at urpla.net
Mon Nov 1 22:00:06 GMT 2010


Hi Phil,

end of July last year, Alexandre Raczynski asked about accessing 
QSharedMemory, and you replied, that:

mutable_data = buffer(sharedMemory.data())

...should give _write_ access to the memory.

Hmm, not here:

$ python
Python 2.6 (r26:66714, Mar 30 2010, 00:30:21) 
[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt4 import QtCore
>>> 
>>> shmem = QtCore.QSharedMemory("xxx")
>>> shmem.create(10)
True
>>> shmem.lock()
True
>>> b = buffer(shmem.data())
>>> repr(b)
'<read-only buffer for 0xb74a37a0, size -1, offset 0 at 0xb6c0f9a0>'
>>> b = buffer(shmem.data(), 0, 10)
>>> repr(b)
'<read-only buffer for 0xb74a3710, size 10, offset 0 at 0xb6c0f9c0>'
>>> 

Both attempts to create a buffer object resulted in read-only buffers, 
that refuse getting modified. I must be doing something wrong, but 
there's not much room left for manoeuvring..

Pete

python: 2.6
sip: 4.12-snapshot-12acbffd0085
qt4: 4.7.0
pyqt4: 4.8.1


More information about the PyQt mailing list