I’m playing with QSharedMemory and I’m not sure if I just found a serious bug or I’m doing something wrong. The case is that docs say that QSharedMemory::create() should return true if no memory with the same key exists, otherwise it should return false and QSharedMemory::error() should be checked to see what happened.
My current code is:
QSharedMemory sm("smtest");
sm.setKey("smtest"); // <--- not needed as I already set the key in the initializator, but I'm leaving it anyways, just for the test
qDebug() << sm.create(1);
qDebug() << sm.create(1); //<--- I expect this to return false, but it returns true.
qDebug() << sm.error(); //<--. I expect this to return QSharedMemory::AlreadyExists, but QSharedMemory::NoError is returned instead.
//wtf?!
My question is: did I just found a really big bug in Qt4 or I’m doing something wrong?
PS: This code is ran on Windows 7 x64
EDIT: Just to make it clear, if I run that code twice, the second app should detect the first one, but it doesn’t.
EDIT 2: I reported a bug here https://bugreports.qt.io/browse/QTBUG-27744
I just run this on Linux:
and on first run got
Could it be that you don’t have QCoreApplication created? A lot of Qt stuff tends to depend on that being created.
Edit: to emphasize, above only happens with first run. Subsequent runs give false-false always.
Edit2: On Windows, result is true-true for me too.
Edit3: Seems to be a bug, sounds awfully lot like this: https://bugreports.qt.io/browse/QTBUG-5123