129#if QT_CONFIG(sharedmemory)
130 Q_Q(QSharedImageLoader);
136 auto shm = std::make_unique<QSharedMemory>(QSharedMemory::legacyNativeKey(q->key(path, params)));
139 if (!shm->attach(QSharedMemory::ReadOnly)) {
140 QImage img = q->loadFile(path, params);
143 size_t size =
sizeof(SharedImageHeader) + img.sizeInBytes();
144 if (size > size_t(std::numeric_limits<
int>::max())) {
145 qCDebug(lcSharedImage) <<
"Image" << path <<
"to large to load";
147 }
else if (shm->create(
int(size))) {
148 qCDebug(lcSharedImage) <<
"Created new shm segment of size" << size <<
"for image" << path;
150 qCDebug(lcSharedImage) <<
"Lock1 failed!?" << shm->errorString();
154 storeImageToMem(shm->data(), img);
155 }
else if (shm->error() == QSharedMemory::AlreadyExists) {
158 if (!shm->attach(QSharedMemory::ReadOnly)) {
159 qCDebug(lcSharedImage) <<
"Attach to existing failed?" << shm->errorString();
163 qCDebug(lcSharedImage) <<
"Create failed?" << shm->errorString();
168 Q_ASSERT(shm->isAttached());
172 qCDebug(lcSharedImage) <<
"Lock2 failed!?" << shm->errorString();
178 if (!verifyMem(shm->constData(), shm->size())) {
179 qCDebug(lcSharedImage) <<
"Verifymem failed!?";
184 QSharedMemory *shmp = shm.release();
185 SharedImageInfo *sii =
new SharedImageInfo;
188 QImage shImg = createImageFromMem(shmp->constData(), sii);
190 if (!shmp->unlock()) {
191 qCDebug(lcSharedImage) <<
"UnLock failed!?";