Solved Connecting QApplication event with QMainWindow instance
-
Hi,
I found this interesting example in the Qt documentation:#include <QApplication> #include <QFileOpenEvent> #include <QtDebug> class MyApplication : public QApplication { public: MyApplication(int &argc, char **argv) : QApplication(argc, argv) { } bool event(QEvent *event) { if (event->type() == QEvent::FileOpen) { QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event); qDebug() << "Open file" << openEvent->file(); } return QApplication::event(event); } };
Now, in my case I have a QMainWindow instance that I want to connect with the QFileOpenEvent. Either MyApplication object and the QMainWindow object are defined in the main.cpp file.
What is the best way to connect those objects when MyApplication::event() method is triggered?
Thanks!
-
@xtingray
Did you try an EventFilter on either of those objects? -
@kenchan Reading the documentation you shared with me I found an easy solution adding this line inside the event() method of MyApplication:
QApplication::sendEvent(mainWindow, event);
Thanks!