Strange issue with QFileOpenEvent on MacOS
I have to subclass QApplication and redefine event function, that waiting for FileOpen event and runs some actions after it comes, and also i created template Info.plist file with extensions of registred filetypes for this application. When i try to open associated file by double mouse click, application have to start and creates main window, but then it crash in QCoreApplication::Arguments and message box from Application::event not executed.
Code:
{
public:
Application
( int argc,
char * argv
[]):QApplication(argc,argv
){}protected:
virtual bool event
(QEvent * event
) {
if( event
->type
() == QEvent::FileOpen ) {
box.setText(static_cast<QFileOpenEvent>(event)->file());
box.exec();
return true;
}
return false;
}
}
But if i create messagebox before event type check(as in code below), it works fine, both messagebox are showing. What could be the the reason for this behavior ?
Code:
{
public:
Application
( int argc,
char * argv
[]):QApplication(argc,argv
){}protected:
virtual bool event
(QEvent * event
) {
msgbox.
setText(QString::number(event
->type
()));
msgbox.exec()
if( event
->type
() == QEvent::FileOpen ) {
box.setText(static_cast<QFileOpenEvent>(event)->file());
box.exec();
return true;
}
return false;
}
}
Re: Strange issue with QFileOpenEvent on MacOS
It likely has nothing to do with the declaration of the QMessageBoxes. By systematically returning true or false from your event() reimplementation, your are disrupting all the default treatment of events by the QApplication object. You could try the following:
Code:
{
public:
Application
( int argc,
char * argv
[]):QApplication(argc,argv
){}protected:
virtual bool event
(QEvent * event
) {
if( event
->type
() == QEvent::FileOpen ) {
box.setText(static_cast<QFileOpenEvent>(event)->file());
box.exec();
}
}
}