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>
This commit is contained in:
parent
5a36ee7028
commit
0d517a1352
@ -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();
|
||||
|
47
examples/widgets/dialogs/standarddialogs/main.mm
Normal file
47
examples/widgets/dialogs/standarddialogs/main.mm
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
#include <QStyleHints>
|
||||
#include <QTranslator>
|
||||
#include <QLocale>
|
||||
#include <QLibraryInfo>
|
||||
|
||||
#include "dialog.h"
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
[NSApplication sharedApplication];
|
||||
NSApplicationLoad();
|
||||
NSApplicationLoad();
|
||||
[NSApp run];
|
||||
|
||||
QApplication app(argc, argv);
|
||||
//app.setAttribute(Qt::AA_DontUseNativeDialogs);
|
||||
|
||||
#if QT_CONFIG(translation)
|
||||
QTranslator translator;
|
||||
if (translator.load(QLocale::system(), u"qtbase"_s, u"_"_s,
|
||||
QLibraryInfo::path(QLibraryInfo::TranslationsPath))) {
|
||||
app.installTranslator(&translator);
|
||||
}
|
||||
#endif
|
||||
|
||||
QGuiApplication::setApplicationDisplayName(Dialog::tr("Standard Dialogs"));
|
||||
|
||||
Dialog dialog;
|
||||
if (!QGuiApplication::styleHints()->showIsFullScreen() && !QGuiApplication::styleHints()->showIsMaximized()) {
|
||||
const QRect availableGeometry = dialog.screen()->availableGeometry();
|
||||
dialog.resize(availableGeometry.width() / 3, availableGeometry.height() * 2 / 3);
|
||||
dialog.move((availableGeometry.width() - dialog.width()) / 2,
|
||||
(availableGeometry.height() - dialog.height()) / 2);
|
||||
}
|
||||
dialog.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user