View Full Version : QSharedMemory, signals and QBuffer

22nd November 2011, 12:52

I am trying to get signals when a QSharedMemory is written to. I tried it a few times in the folowing way:

QSharedMemory *sm = new QSharedMemory("key", this);
QByteArray *ba;
QBuffer *buff;
ba = new QByteArray();
ba->setRawData((char*)sm->data(), sm->size());
buff = new QBuffer(ba, this);
connect(buff, SIGNAL(readyRead()), this, SLOT(bufferReadyRead()));

memset(sm->data(), NULL, sm->size());
QByteArray response = myDomDoc.toByteArray();

memcpy((char*)sm->data(), response.data(), sm->size()-1);
// Here I want the QBuffer's readyRead() signal to emit

My attempt might be a little contorted but I hope you get the idea. I am trying to wrap a QBuffer around a QSharedMemory data so that I can get a signal when somebody writes to the QSharedMemory.

Is this a good way to do this? Is there a better way to do it? If not what is best way to get a signal when my QSharedMemory is written to.

Best regards.

23rd November 2011, 06:06
I think the problem is that as soon as I write to the shared memory data the QByteArray implements a copy-on-write and therefore the QBuffer does not detect something written to its data.

am I right?