Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Where to intercept (mac os) QFileOpenEvent ?

[Solved] Where to intercept (mac os) QFileOpenEvent ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vaquita Tim
    wrote on last edited by
    #1

    I'm getting my Qt app working on Mac OS now (it's running nicely on Windows). So, I want to open documents which the user double-clicks on in the Finder, which means responding to QFileOpen events. All fine.
    I've read the QCoreApplication docs (http://qt-project.org/doc/qt-5/qcoreapplication.html#notify) and I suppose an override of QApplication::notify() should be the preferred option. However, I don't currently have a sub-class of QApplication in my project, so I'm thinking to implement QObject::event() for my QMainWindow sub-class. Yes, basically I'm lazy*.
    So, the question I have really, is, does anyone have any suggestion as to where best to intercept these events ? Since I don't really understand the event handling routes within Qt, I'm not sure if this would be a lot less efficient** than implementing a QApplication sub-class. I'm sure it will make very little difference in terms of the structure of the classes in my design. But if it saves a few ops if I do a bit more typing, it all goes to save the planet…

    Tim

    • I like to think, efficient
      ** I don't see why my apps cannot be lazy too :-)
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Long time since I played with that but IIRC, you can simply handle it in the event function of e.g. your QMainWindow subclass

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vaquita Tim
        wrote on last edited by
        #3

        bq. handle it in the event function of e.g. your QMainWindow subclass

        Apparently not, it seems. At least, that's what I tried, but the event never gets that far. In the docs for QFileOpenEvent, it specifically states that the event is sent to the QApplication::instance(). And I guess it stops there...
        So, I bit the bullet, sub-classed QApplication, and overrode event(), sending it directly to my QMainWIndow. It's not pretty :-
        @bool PGazetteApp::event( QEvent * a_pEvent)
        {
        // Intercept FileOpen events
        if( a_pEvent && a_pEvent->type()==QEvent::FileOpen )
        { // Send file open events to the Main Window
        QWindowList WinList( topLevelWindows() );
        QWindowList::iterator pIt = WinList.begin();
        if( pIt == WinList.end() )
        return false;

        QWindow * pMainWin( *pIt );
        return sendEvent( pMainWin, a_pEvent );
        }
        return QApplication::event( a_pEvent );
        }
        @

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved