summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-03-08 16:38:58 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-03-09 17:15:53 +0100
commit054fb061d770205706e80e80b6937edf7c866da1 (patch)
treeb84790c333e5529117810017922fe1eb01a62598 /src/gui
parenta6776de0c70d23ac197682c7bef603450cb8b03f (diff)
Fix warnings from deprecating QFileOpenEvent::openFile, update snippet
Amends 76c63936d3d3c937960108da88a56394a0ac70b5 by adjusting the test case. We still just test that we can open a file based on a filename that we came up with ourselves. Also, update usage documentation and make the snippet a bit more relevant. Change-Id: I5bf00210d74e2a73d5a71a09a5beb1b3f6f8e225 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/doc/snippets/qfileopenevent/main.cpp12
-rw-r--r--src/gui/kernel/qevent.cpp9
2 files changed, 17 insertions, 4 deletions
diff --git a/src/gui/doc/snippets/qfileopenevent/main.cpp b/src/gui/doc/snippets/qfileopenevent/main.cpp
index b733bfc320..a94ff58137 100644
--- a/src/gui/doc/snippets/qfileopenevent/main.cpp
+++ b/src/gui/doc/snippets/qfileopenevent/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2016 Samuel Gaist <samuel.gaist@edeltech.ch>
+// Copyright (C) 2023 Samuel Gaist <samuel.gaist@edeltech.ch>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
//! [QApplication subclass]
@@ -19,7 +19,15 @@ public:
{
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
- qDebug() << "Open file" << openEvent->file();
+ const QUrl url = openEvent->url();
+ if (url.isLocalFile()) {
+ QFile localFile(url.toLocalFile());
+ // read from local file
+ } else if (url.isValid()) {
+ // process according to the URL's schema
+ } else {
+ // parse openEvent->file()
+ }
}
return QApplication::event(event);
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 8e871d7694..8040a3647b 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -3594,10 +3594,15 @@ Q_IMPL_EVENT_COMMON(QShowEvent)
\snippet qfileopenevent/Info.plist Custom Info.plist
- The following implementation of a QApplication subclass prints the path to
- the file that was, for example, dropped on the Dock icon of the application.
+ The following implementation of a QApplication subclass shows how to handle
+ QFileOpenEvent to open the file that was, for example, dropped on the Dock
+ icon of the application.
\snippet qfileopenevent/main.cpp QApplication subclass
+
+ Note how \c{QFileOpenEvent::file()} is not guaranteed to be the name of a
+ local file that can be opened using QFile. The contents of the string depend
+ on the source application.
*/
/*!