Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 Samuel Gaist <samuel.gaist@edeltech.ch>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//! [QApplication subclass]
5#include <QApplication>
6#include <QDebug>
7#include <QFile>
8#include <QFileOpenEvent>
9#include <QPushButton>
10
12{
13public:
14 MyApplication(int &argc, char **argv)
16 {
17 }
18
19 bool event(QEvent *event) override
20 {
21 if (event->type() == QEvent::FileOpen) {
22 QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
23 const QUrl url = openEvent->url();
24 if (url.isLocalFile()) {
25 QFile localFile(url.toLocalFile());
26 // read from local file
27 } else if (url.isValid()) {
28 // process according to the URL's schema
29 } else {
30 // parse openEvent->file()
31 }
32 }
33
34 return QApplication::event(event);
35 }
36};
37//! [QApplication subclass]
38
39int main(int argc, char *argv[])
40{
41 MyApplication app(argc, argv);
42 QPushButton closeButton("Quit");
43 QObject::connect(&closeButton, &QPushButton::clicked, &app, &QApplication::quit);
44 closeButton.show();
45 return app.exec();
46}
[QApplication subclass]
Definition main.cpp:12
MyApplication(int &argc, char **argv)
Definition main.cpp:14
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition main.cpp:19
int main(int argc, char *argv[])
[ctor_close]