Reputation: 1319
I'm writing an app using Qt5. That app runs on Window, Linux and now on MacOS.
In order to make sure my app meets the apple's requirements, I would like to add entries in the application menu (preferences, about...).
Does anyone know how to do so ?
An old doc about Qt4.8 describes that the menu is handle by Qt but it doesn't describe what to do.
Upvotes: 3
Views: 840
Reputation: 6059
I saw this question and was looking for an answer. The comments were helpful, but here is a more complete code example that should help others out.
mainwindow.h: Add these include statements
#include <QMenu>
#include <QAction>
...
private:
Ui::MainWindow *ui;
QMenu *mainMenu;
QAction *aboutAction;
mainwindow.cpp: initializer function
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
this->aboutAction = new QAction(0);
this->aboutAction->setMenuRole(QAction::AboutRole);
ui->setupUi(this);
this->mainMenuBar = new QMenuBar(0);
this->mainMenu = new QMenu(0);
this->mainMenuBar->addMenu(this->mainMenu);
this->mainMenu->addAction(this->aboutAction);
this->setMenuBar(this->mainMenuBar);
}
Using QT 5.3.2 and Snow Leopard OS X 10.6.8, QT Creator 3.0.1.
Since you are using the AboutRole
, there is no need to specify the QString parameter of QAction. It automatically defaults to what you want.
Upvotes: 5