Part of implementation in Qt Creator:
void MainWindow::openRecentFile()
{
QAction *a
= qobject_cast<QAction
*>
(sender
());
if (m_recentFilesActions.contains(a)) {
editorManager()->openEditor(m_recentFilesActions.value(a));
editorManager()->ensureEditorManagerVisible();
}
}
void MainWindow::openRecentFile()
{
QAction *a = qobject_cast<QAction*>(sender());
if (m_recentFilesActions.contains(a)) {
editorManager()->openEditor(m_recentFilesActions.value(a));
editorManager()->ensureEditorManagerVisible();
}
}
To copy to clipboard, switch view to plain text mode
So it seems that one way is to set file path as a text for each action and connect all actions to one slot:
connect(my_action,SIGNAL(triggered(),this,SLOT(openFile()));
connect(my_action,SIGNAL(triggered(),this,SLOT(openFile()));
To copy to clipboard, switch view to plain text mode
And then, in openFile(), with a QObject::sender() you can get sender, it means the action that triggered that slot.
QAction *a
= qobject_cast<QAction
*>
(sender
());
QAction *a = qobject_cast<QAction*>(sender());
To copy to clipboard, switch view to plain text mode
and now:
a->text();
a->text();
To copy to clipboard, switch view to plain text mode
gives you QString with a file path to open.
So you can use your previosly created slot:
openFiles(a->text());
openFiles(a->text());
To copy to clipboard, switch view to plain text mode
Of course it would be nice to also add some error checking.
P.S. Notice that in the example given by my preposter the QSettings class is used instead of saving recent files to some file.
Bookmarks