PDA

View Full Version : QSharedMemory problem



produktdotestow
18th November 2010, 20:11
hi,
i have small (i hope it's small) problem.

at first i run process1 and after - process2.

process1 code:

QSharedMemory sharedMemory("foobar");
sharedMemory.create(1024);
sharedMemory.lock();
QString *to = (QString*)sharedMemory.data();
QString *text = new QString("hello world");
memcpy(to, text, sizeof(*text));
sharedMemory.unlock();

process2 code:

QSharedMemory sharedMemory("foobar");
sharedMemory.attach();
sharedMemory.lock();
QString *to = (QString*)sharedMemory.data();
ui->plainTextEdit->setPlainText(*to);
sharedMemory.unlock();

this code makes process2 crash.
what's wrong with it?

thanks.

high_flyer
18th November 2010, 20:43
Try:


QString to = QByteArray((char*)sharedMomory.constData(),sharedM omory,size());
ui->plainTextEdit->setPlainText(to);


If you run your app in a debugger you will see which line exactly crashes, and why.

produktdotestow
18th November 2010, 21:08
there
http://www.qtcentre.org/threads/26254-QSharedMemory-and-C-objects
i found the reason why it doesn't work.

thanks for your help :)