Results 1 to 2 of 2

Thread: QSharedMemory, signals and QBuffer

  1. #1
    Join Date
    Dec 2010
    Posts
    44
    Thanks
    9
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QSharedMemory, signals and QBuffer

    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.

  2. #2
    Join Date
    Dec 2010
    Posts
    44
    Thanks
    9
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSharedMemory, signals and QBuffer

    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?

Similar Threads

  1. Size Of QBuffer Not Correct?
    By justin123 in forum Qt Programming
    Replies: 2
    Last Post: 20th April 2011, 03:10
  2. QBuffer::readLine()
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2010, 21:57
  3. how can convert QFile to QBuffer?
    By learning_qt in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2009, 14:34
  4. QBuffer bytesWritten() problem
    By QAlex in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 10:05
  5. Why is QBuffer's close call so slow?
    By eekisa in forum Qt Programming
    Replies: 4
    Last Post: 8th April 2009, 13:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.