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.
{
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;
}
}
class Application : QApplication
{
public:
Application( int argc, char * argv[]):QApplication(argc,argv){}
protected:
virtual bool event(QEvent * event )
{
if( event->type() == QEvent::FileOpen )
{
QMessageBox box;
box.setText(static_cast<QFileOpenEvent>(event)->file());
box.exec();
return true;
}
return false;
}
}
To copy to clipboard, switch view to plain text mode
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 ?
{
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;
}
}
class Application : QApplication
{
public:
Application( int argc, char * argv[]):QApplication(argc,argv){}
protected:
virtual bool event(QEvent * event )
{
QMessageBox msgbox;
msgbox.setText(QString::number(event->type()));
msgbox.exec()
if( event->type() == QEvent::FileOpen )
{
QMessageBox box;
box.setText(static_cast<QFileOpenEvent>(event)->file());
box.exec();
return true;
}
return false;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks