summaryrefslogtreecommitdiffstats
path: root/src/gui/doc/snippets/qfileopenevent/main.cpp
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/doc/snippets/qfileopenevent/main.cpp
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/doc/snippets/qfileopenevent/main.cpp')
-rw-r--r--src/gui/doc/snippets/qfileopenevent/main.cpp12
1 files changed, 10 insertions, 2 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);