Skip to content

Instantly share code, notes, and snippets.

@alex-spataru
Last active August 29, 2015 14:14
Show Gist options
  • Save alex-spataru/33332ea08bf4c13b6b48 to your computer and use it in GitHub Desktop.
Save alex-spataru/33332ea08bf4c13b6b48 to your computer and use it in GitHub Desktop.
Open files from system request on Mac [Qt]
#include <QEvent>
#include <QApplication>
// Create a subclass of QApplication so that we can customize what we
// do when the operating system sends us an event (such as opening a file)
class MyApp : public QApplication
{
Q_OBJECT
protected:
bool event (QEvent *event)
{
// The system requested us to open a file
if (event->type() == QEvent::FileOpen)
{
// Get the path of the file that we want to open
QString _file_path = static_cast<QFileOpenEvent *> (event)->file();
// Now type the code to open the file in your window here...
}
// The system requested us to do another thing, so we just follow the rules
else
return QApplication::event (event);
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment