summaryrefslogtreecommitdiffstats
path: root/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp
blob: 45e7accfd681a1e542c3105e25978e2c74a7780d (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
#include <QtGui>
#include <QApplication>
#include <QEvent>

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

    bool event(QEvent * event)
    {
        if (event->type() == QEvent::FileOpen) {
            QFileOpenEvent* ev = static_cast<QFileOpenEvent *>(event);
            QFile file;
            bool ok = ev->openFile(file, QFile::Append | QFile::Unbuffered);
            if (ok)
                file.write(QByteArray("+external"));
            return true;
        } else {
            return QApplication::event(event);
        }
    }
};

int main(int argc, char *argv[])
{
    MyApplication a(argc, argv);
    a.sendPostedEvents(&a, QEvent::FileOpen);
    return 0;
}