I also tried to get my Qt-based application to handle a custom URL scheme on a Mac and go the same way as the original poster. It turns out that Qt4 already supports URL events on Mac, and there is no need to write Objective-C code to receive them. This is essentially the reason that you did not receive any URL events when you set up an event handler in response to NSApplicationWillFinishLaunchingNotification: Qt then registers its own handler.
When the URL with your custom schema starts, your Qt application will receive a FileOpenEvent file. Note that the QApplication instance accepts the event. You can catch it by subclassing the QApplication application or by setting an event filter in standard QApplication. I chose this second approach.
Here's the eventFilter method of my custom event filter class, FileOpenEventFilter. It just emits a urlOpened signal when the event contains a non-empty URL. It also saves the last open URL if my main window is not fully initialized when an event arrives (which happens in my application when it is not already running when I click on a custom URL).
bool FileOpenEventFilter::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::FileOpen) { QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event); if (!fileEvent->url().isEmpty()) { m_lastUrl = fileEvent->url().toString(); emit urlOpened(m_lastUrl); } else if (!fileEvent->file().isEmpty()) { emit fileOpened(fileEvent->file()); } return false; } else {
Chris laurel
source share