Qt4: how to send QString inside a struct via QSharedMemory -


i have struct

struct control_data{     int column_number;     qstring cell; }; 

i need send thread of qsharememory. read can't because qstring contains pointers inside. other ways?

you have serialize struct byte array. can convert qstring const char* this:

mystring.tostdstring().c_str(); 

but serializing qstring should work.

  • the first step serialize struct qdatastream using qt, example here.

  • then once struct can read , written can pass shared memory.

a complete example of using qsharedmemory can found here.

here relevant code:

// first, test whether shared memory segment attached process. // if so, detach if (sharedmem.isattached()) {     sharedmem.detach(); }  ...  qbuffer buffer; buffer.open( qbuffer::readwrite ); qdatastream out( &buffer ); out << youstruct; int size = buffer.size();  // size of int + size of qstring in bytes  if ( !sharedmem.create( size ) ) {     return; }  // write shared memory sharedmem.lock(); char *to = (char*)sharedmem.data(); const char *from = buffer.data().data(); memcpy( to, from, qmin( sharedmem.size(), size ) ); sharedmem.unlock(); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -