sky
22nd November 2011, 11:52
Hi,
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;
if(sm->create(1024))
{
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();
sm->lock();
buff->open(QIODevice::ReadWrite);
memcpy((char*)sm->data(), response.data(), sm->size()-1);
buff->close();
// Here I want the QBuffer's readyRead() signal to emit
sm->unlock();
}
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.
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;
if(sm->create(1024))
{
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();
sm->lock();
buff->open(QIODevice::ReadWrite);
memcpy((char*)sm->data(), response.data(), sm->size()-1);
buff->close();
// Here I want the QBuffer's readyRead() signal to emit
sm->unlock();
}
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.