summaryrefslogtreecommitdiffstats
path: root/src/gui/doc/snippets/qfileopenevent/main.cpp
blob: b733bfc320e733ed21a7b43f74e28afeeb45595b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (C) 2016 Samuel Gaist <samuel.gaist@edeltech.ch>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

//! [QApplication subclass]
#include <QApplication>
#include <QDebug>
#include <QFileOpenEvent>
#include <QPushButton>

class MyApplication : public QApplication
{
public:
    MyApplication(int &argc, char **argv)
        : QApplication(argc, argv)
    {
    }

    bool event(QEvent *event) override
    {
        if (event->type() == QEvent::FileOpen) {
            QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
            qDebug() << "Open file" << openEvent->file();
        }

        return QApplication::event(event);
    }
};
//! [QApplication subclass]

int main(int argc, char *argv[])
{
    MyApplication app(argc, argv);
    QPushButton closeButton("Quit");
    QObject::connect(&closeButton, &QPushButton::clicked, &app, &QApplication::quit);
    closeButton.show();
    return app.exec();
}