Results 1 to 2 of 2

Thread: Strange issue with QFileOpenEvent on MacOS

  1. #1
    Join Date
    Aug 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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.

    Qt Code:
    1. class Application : QApplication
    2. {
    3. public:
    4. Application( int argc, char * argv[]):QApplication(argc,argv){}
    5. protected:
    6. virtual bool event(QEvent * event )
    7. {
    8. if( event->type() == QEvent::FileOpen )
    9. {
    10. box.setText(static_cast<QFileOpenEvent>(event)->file());
    11. box.exec();
    12. return true;
    13. }
    14. return false;
    15. }
    16.  
    17. }
    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 ?

    Qt Code:
    1. class Application : QApplication
    2. {
    3. public:
    4. Application( int argc, char * argv[]):QApplication(argc,argv){}
    5. protected:
    6. virtual bool event(QEvent * event )
    7. {
    8. QMessageBox msgbox;
    9. msgbox.setText(QString::number(event->type()));
    10. msgbox.exec()
    11. if( event->type() == QEvent::FileOpen )
    12. {
    13. box.setText(static_cast<QFileOpenEvent>(event)->file());
    14. box.exec();
    15. return true;
    16. }
    17. return false;
    18. }
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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:
    Qt Code:
    1. class Application : QApplication
    2. {
    3. public:
    4. Application( int argc, char * argv[]):QApplication(argc,argv){}
    5. protected:
    6. virtual bool event(QEvent * event )
    7. {
    8. if( event->type() == QEvent::FileOpen )
    9. {
    10. box.setText(static_cast<QFileOpenEvent>(event)->file());
    11. box.exec();
    12. }
    13. return QApplication::event(event);
    14. }
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Strange Compilation issue
    By NicholasSmith in forum Newbie
    Replies: 3
    Last Post: 4th September 2009, 14:40
  2. Application.app/Contents/MacOS file issue
    By sgmurphy19 in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2008, 09:03
  3. QFileOpenEvent on Gnome
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 11th November 2007, 21:28
  4. Strange dependencies when compiling on MacOS
    By pir in forum Installation and Deployment
    Replies: 0
    Last Post: 14th November 2006, 13:49
  5. Another MacOS issue ?!
    By Nemo in forum Qt Programming
    Replies: 3
    Last Post: 14th February 2006, 09:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.