diff options
author | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-03-07 16:53:34 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-03-07 17:08:56 +0100 |
commit | f93032848e6b090b671d0035557a32bed65d2b4e (patch) | |
tree | 8cb6a0705c19d3cc6002f70ed5dddd0dd7adcab9 /examples | |
parent | bcd88d8e9984bff664740aae3cff708a069dbbdd (diff) | |
parent | d0cdc7ad1e2728caf363abf328b2ad81f2ed5a5b (diff) |
Merge remote-tracking branch 'origin/5.6.0' into 5.7v5.7.0-alpha1
Change-Id: Idcda6d52266f557ce4a819b6669f6797473a48a2
Diffstat (limited to 'examples')
-rw-r--r-- | examples/widgets/mainwindows/application/mainwindow.cpp | 16 | ||||
-rw-r--r-- | examples/widgets/mainwindows/application/mainwindow.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/examples/widgets/mainwindows/application/mainwindow.cpp b/examples/widgets/mainwindows/application/mainwindow.cpp index 86dfae166f..861b908189 100644 --- a/examples/widgets/mainwindows/application/mainwindow.cpp +++ b/examples/widgets/mainwindows/application/mainwindow.cpp @@ -59,6 +59,10 @@ MainWindow::MainWindow() connect(textEdit->document(), &QTextDocument::contentsChanged, this, &MainWindow::documentWasModified); + QGuiApplication::setFallbackSessionManagementEnabled(false); + connect(qApp, &QGuiApplication::commitDataRequest, + this, &MainWindow::commitData); + setCurrentFile(QString()); setUnifiedTitleAndToolBarOnMac(true); } @@ -383,3 +387,15 @@ QString MainWindow::strippedName(const QString &fullFileName) return QFileInfo(fullFileName).fileName(); } //! [49] + +void MainWindow::commitData(QSessionManager &manager) +{ + if (manager.allowsInteraction()) { + if (!maybeSave()) + manager.cancel(); + } else { + // Non-interactive: save without asking + if (textEdit->document()->isModified()) + save(); + } +} diff --git a/examples/widgets/mainwindows/application/mainwindow.h b/examples/widgets/mainwindows/application/mainwindow.h index 08b4aa17f5..9712604125 100644 --- a/examples/widgets/mainwindows/application/mainwindow.h +++ b/examples/widgets/mainwindows/application/mainwindow.h @@ -47,6 +47,7 @@ QT_BEGIN_NAMESPACE class QAction; class QMenu; class QPlainTextEdit; +class QSessionManager; QT_END_NAMESPACE //! [0] @@ -69,6 +70,7 @@ private slots: bool saveAs(); void about(); void documentWasModified(); + void commitData(QSessionManager &); private: void createActions(); |