I've googled a lot, but still unable to find nice solution :/
So, i'm porting one complicated Qt5 application (client of some network service) to Mac OS X (10.7.0 "Lion" and higher).
I need to handle custom file like *.xyz
and custom URL scheme like xyz://
.
Okay, Qt5 has the QFileOpenEvent
class to handle OS X appropriate event.
BUT: this event arrives only after the application event loop starts (obviously)!
And i need to "catch" and handle OS X' file open event BEFORE main
starts, because the program logic was designed to take care of the command line argument handling only.
The simplified main
function code:
int main(int argc, char[]* argv)
{
QApplication app( argc, argv );
QStringList arguments = app.arguments();
if( arguments.count() == argc ) arguments.removeFirst();
Logic appLogic( NULL, &app );
app.installMessageHandler( &appLogic );
// The problem:
// **This function will always called earlier than the any event**
if( ! appLogic.start( arguments ) ) return 0;
// Start processing of events
// Only after this call Logic class get the desired event
return app.exec();
}
Is there a way to get an OS X' file opening event before the C++ main
function starts, or to get "my" file/url in the argv
parameter?
Maybe, some Objective-C
black magic does the job?
NOTE: start
does many complicated - and asynchronous - things. Event arrives during it's execution, so it's hard to handle it when the async stuff is already working. So looks like i just need to prevent start
execution, if the event will arrive.
If the application is already opened, there is no problem.