Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
11
class
MyApplication
:
public
QApplication
12
{
13
public
:
14
MyApplication
(
int
&argc,
char
**argv)
15
:
QApplication
(
argc
,
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
39
int
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
}
MyApplication
[QApplication subclass]
Definition
main.cpp:12
MyApplication::MyApplication
MyApplication(int &argc, char **argv)
Definition
main.cpp:14
MyApplication::event
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
main
int main(int argc, char *argv[])
[ctor_close]
Definition
src_corelib_animation_qpropertyanimation.cpp:100
qtbase
src
gui
doc
snippets
qfileopenevent
main.cpp
Generated on
for Qt by
1.18.0