qt6windows7/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp

34 lines
891 B
C++
Raw Normal View History

2023-10-30 06:33:08 +08:00
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtGui>
#include <QEvent>
struct MyApplication : public QGuiApplication
{
MyApplication(int& argc, char** argv)
: QGuiApplication(argc, argv)
{}
bool event(QEvent * event) override
{
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent* ev = static_cast<QFileOpenEvent *>(event);
2023-11-02 05:23:55 +08:00
QFile file(ev->file());
bool ok = file.open(QFile::Append | QFile::Unbuffered);
2023-10-30 06:33:08 +08:00
if (ok)
file.write(QByteArray("+external"));
return true;
} else {
return QGuiApplication::event(event);
}
}
};
int main(int argc, char *argv[])
{
MyApplication a(argc, argv);
a.sendPostedEvents(&a, QEvent::FileOpen);
return 0;
}