Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
5#include <QApplication>
6#include <QDebug>
7#include <QFileOpenEvent>
8#include <QPushButton>
9
11{
12public:
13 MyApplication(int &argc, char **argv)
14 : QApplication(argc, argv)
15 {
16 }
17
18 bool event(QEvent *event) override
19 {
20 if (event->type() == QEvent::FileOpen) {
21 QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
22 const QUrl url = openEvent->url();
23 if (url.isLocalFile()) {
24 QFile localFile(url.toLocalFile());
25 // read from local file
26 } else if (url.isValid()) {
27 // process according to the URL's schema
28 } else {
29 // parse openEvent->file()
30 }
31 }
32
34 }
35};
37
38int main(int argc, char *argv[])
39{
40 MyApplication app(argc, argv);
41 QPushButton closeButton("Quit");
43 closeButton.show();
44 return app.exec();
45}
[QApplication subclass]
Definition main.cpp:11
MyApplication(int &argc, char **argv)
Definition main.cpp:13
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:18
void clicked(bool checked=false)
This signal is emitted when the button is activated (i.e., pressed down then released while the mouse...
The QApplication class manages the GUI application's control flow and main settings.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
bool event(QEvent *) override
\reimp
static void quit()
\threadsafe
\inmodule QtCore
Definition qcoreevent.h:45
The QFileOpenEvent class provides an event that will be sent when there is a request to open a file o...
Definition qevent.h:847
QUrl url() const
Returns the url that the application should open.
Definition qevent.h:854
\inmodule QtCore
Definition qfile.h:93
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
The QPushButton widget provides a command button.
Definition qpushbutton.h:20
\inmodule QtCore
Definition qurl.h:94
bool isLocalFile() const
Definition qurl.cpp:3431
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
Definition qurl.cpp:1874
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
Definition qurl.cpp:3411
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7956
int main()
[0]
struct _cl_event * event
QUrl url("example.com")
[constructor-url-reference]
QApplication app(argc, argv)
[0]