PDA

View Full Version : QSharedMemory won't attach



MattPhillips
25th November 2009, 19:44
Hello,

This is happening both with qt examples and my own sample code. Specifically, when I execute this:


QSharedMemory* mem = new QSharedMemory("testkey");
mem->create(sizeof(int));
if (mem->attach())
qDebug() << "Successful attach()";
else
qDebug() << "attach() failed, code " << mem->error() << ", " << mem->errorString();


I get this:


attach() failed, code 0 , ""

The same thing happens with the examples (examples/ipc/sharedmemory and another one from Nokia that displays images). The attach fails yet no error flag is thrown. Moreover this happens on Max 10.5, Windows XP, and Ubuntu 9.10; I'm using Qt 4.5.3. Does anybody know what's going on? Thank you--

Matt

Corinzio
26th November 2009, 09:03
Quite strange!

mem->error() return 0 from the docs it means:
QSharedMemory::NoError (http://doc.trolltech.com/4.5/qsharedmemory.html#SharedMemoryError-enum)

check your if statement ( the one you posted look good to me but it seems the problem is there...... :confused:)

Good Luck


ops maybe create already attach the shared memory?

caduel
26th November 2009, 09:30
ops maybe create already attach the shared memory?
the docs say: yes, create does attach (see QSharedMemory::create())

MattPhillips
27th November 2009, 15:45
Thanks guys! Running QSharedMemory::isAttached() after creation returned true so I think that was my problem (doh!). The Qt IPC dialog example does in fact work just fine, I wasn't running it correctly, however this one doesn't:

http://www.forum.nokia.com/info/sw.nokia.com/id/ff196071-b2d7-417c-b172-f230ff85abd2/Qt_for_S60_QSharedMemory_Example.html

--haven't figured out why. Possibly for a completely different reason though. Anyway, thanks--

Matt