summaryrefslogtreecommitdiffstats
path: root/examples/corelib
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-11-11 11:40:15 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-11-15 12:27:43 +0100
commit0d517a13525faaedd17dafe10b091284806e18a9 (patch)
tree157070d953d94668acde3cbbac9e7b608b758924 /examples/corelib
parent5a36ee7028b9138639a6c821056d9c69e8092e7f (diff)
sharedmemory example: Handle QSharedMemory::AlreadyExists by attaching
Not all platforms clean up the shared memory entries on exit, so the example needs to handle that case, by attaching instead, as documented. Change-Id: Ifbcf92d0fad429caf30710bd8a344831cb0d859c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'examples/corelib')
-rw-r--r--examples/corelib/ipc/sharedmemory/dialog.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/examples/corelib/ipc/sharedmemory/dialog.cpp b/examples/corelib/ipc/sharedmemory/dialog.cpp
index ac171ef943..b656cc0c67 100644
--- a/examples/corelib/ipc/sharedmemory/dialog.cpp
+++ b/examples/corelib/ipc/sharedmemory/dialog.cpp
@@ -89,9 +89,13 @@ void Dialog::loadFromFile()
int size = buffer.size();
if (!sharedMemory.create(size)) {
- ui.label->setText(tr("Unable to create shared memory segment: %1")
- .arg(sharedMemory.errorString()));
- return;
+ if (sharedMemory.error() == QSharedMemory::AlreadyExists) {
+ sharedMemory.attach();
+ } else {
+ ui.label->setText(tr("Unable to create or attach to shared memory segment: %1")
+ .arg(sharedMemory.errorString()));
+ return;
+ }
}
sharedMemory.lock();
char *to = (char*)sharedMemory.data();