Last active
August 29, 2015 14:14
-
-
Save alex-spataru/33332ea08bf4c13b6b48 to your computer and use it in GitHub Desktop.
Open files from system request on Mac [Qt]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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