Hi,

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

Qt Code:
  1. QSharedMemory *sm = new QSharedMemory("key", this);
  2. QBuffer *buff;
  3. if(sm->create(1024))
  4. {
  5. ba = new QByteArray();
  6. ba->setRawData((char*)sm->data(), sm->size());
  7. buff = new QBuffer(ba, this);
  8. connect(buff, SIGNAL(readyRead()), this, SLOT(bufferReadyRead()));
  9.  
  10. memset(sm->data(), NULL, sm->size());
  11. QByteArray response = myDomDoc.toByteArray();
  12.  
  13. sm->lock();
  14. buff->open(QIODevice::ReadWrite);
  15. memcpy((char*)sm->data(), response.data(), sm->size()-1);
  16. buff->close();
  17. // Here I want the QBuffer's readyRead() signal to emit
  18. sm->unlock();
  19. }
To copy to clipboard, switch view to plain text mode 

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.