If you have subclassed QApplication already, then just add a signal to it:
// MyApplication.h
{
//...
signals:
void openFile
( const QString & fileName
);
};
// MyApplication.h
class MyApplication : public QApplication
{
//...
signals:
void openFile( const QString & fileName );
};
To copy to clipboard, switch view to plain text mode
and in your event handler, emit that signal with the file name after you have verified that the file is of the right type for your app, etc.
In your MainWindow class, add a public slot and connect to it in main(). Implement the slot in MainWindow.cpp to do whatever it needs to do.
// MainWindow.h
class MainWindow : public QMainWIndow
{
// ...
public slots:
void onOpenFile
( const QString & fileName
);
};
// main.cpp
int main( /* ... */ )
{
MyApplication myApp;
MainWindow myMain;
connect ( &myApp, &MyApplication::openFile, &myMain, &MainWindow::onOpenFile );
myMain.show();
return myApp.exec();
}
// MainWindow.h
class MainWindow : public QMainWIndow
{
// ...
public slots:
void onOpenFile( const QString & fileName );
};
// main.cpp
int main( /* ... */ )
{
MyApplication myApp;
MainWindow myMain;
connect ( &myApp, &MyApplication::openFile, &myMain, &MainWindow::onOpenFile );
myMain.show();
return myApp.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks