Unable to read shared memory data using boost created by Qt -


i've created qt shared memory program write string shared memory. after writing, need read boost program. tried using simple programs, couldn't read string using boost interprocess.

here qt code writing shared memory. , i'm double checking if string written reading shared memory same program.

void cdialog::loadstring() {     if(sharedmemory.isattached())     {         if(!sharedmemory.detach())         {             lbl->settext("unable detach shared memory");             return;         }     }      lbl->settext("click on top button");      char sstring[] = "my string";      qbuffer buffer;     buffer.open(qbuffer::readwrite);      qdatastream out(&buffer);     out << sstring;      int size = buffer.size();     qdebug() << size;      if(!sharedmemory.create(size))     {         lbl->settext("unable create shared memory segment");         qdebug() << lbl->text();     }     sharedmemory.lock();     char *to = (char *) sharedmemory.data();     const char *from = buffer.data();     memcpy(to, from, qmin(sharedmemory.size(), size));     sharedmemory.unlock();      char * str;     qdatastream in(&buffer);     sharedmemory.lock();     buffer.setdata((char *)sharedmemory.constdata(), sharedmemory.size());     buffer.open(qbuffer::readonly);     in >> str;     sharedmemory.unlock();     qdebug() << str; } 

and i'm reading boost using same key i've provided in qt program. below boost program code -

int main() {   boost::interprocess::shared_memory_object shdmem(boost::interprocess::open_only, "highscore", boost::interprocess::read_only);    boost::interprocess::offset_t size;    if (shdmem.get_size(size))      std::cout << "shared mem size: " << size << std::endl;     boost::interprocess::mapped_region region2(shdmem, boost::interprocess::read_only);    char *i2 = static_cast<char *>(region2.get_address());    std::cout << i2 << std::endl;   return 0; } 

kindly me in reading shared memory data boost program. thank you.

from qt docs:

warning: qsharedmemory changes key in qt-specific way. therefore not possible use shared memory of non-qt applications qsharedmemory.

you need use boost on both sides.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -