Using the following example code the native menu on MacOS 10.9.5 using Qt 5.3.2 does not show up when starting the application. The former menu remains visible but no actions can be performed with this toolbar. If I switch to another application or to another desktop, the menu of this application becomes visible and usable as expected.
My questions is pretty much the same as the following one, but the answer does not work for my code:
There is another very similar question here and I already modified my code according to the suggested answer, but it does not work either:
MenuBar Not Showing for Simple QMainWindow Code, Qt Creator Mac OS
#include <QtGui>
#include <QtWidgets>
class MainWindow : public QMainWindow
{
public:
MainWindow();
private:
void create_actions_();
void create_menus_();
void about_();
void dummy_();
QMenuBar* menu_bar_;
QMenu* file_menu_;
QMenu* help_menu_;
QAction* action_about_;
QAction* action_dummy_;
};
MainWindow::MainWindow()
{
resize(800, 600);
create_actions_();
create_menus_();
}
void MainWindow::create_actions_()
{
action_about_ = new QAction(tr("About"), this);
action_dummy_ = new QAction(tr("Dummy"), this);
connect(action_about_, &QAction::triggered, this, &MainWindow::about_);
connect(action_dummy_, &QAction::triggered, this, &MainWindow::dummy_);
}
void MainWindow::create_menus_()
{
menu_bar_ = new QMenuBar(this);
file_menu_ = new QMenu(tr("&File"));
file_menu_->addAction(action_dummy_);
menu_bar_->addAction(file_menu_->menuAction());
help_menu_ = new QMenu(tr("&Help"));
help_menu_->addAction(action_about_);
menu_bar_->addAction(help_menu_->menuAction());
menu_bar_->setNativeMenuBar(true);
}
void MainWindow::about_()
{
QMessageBox::about(this, tr("About"), tr("FooBar"));
}
void MainWindow::dummy_()
{
QMessageBox::about(this, tr("Dummy"), tr("Dummy"));
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow main_window;
main_window.show();
return app.exec();
}
I am really sorry that I bring up the same question again, but I am not allowed to make any comments as a newbie (which frankly sucks!).
Edit: I'm using the following CMake file to build the test project:
cmake_minimum_required(VERSION 2.8.12)
project(testproject)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets)
add_executable(testapp main.cpp mainwindow.h mainwindow.cpp)
target_link_libraries(testapp Qt5::Widgets)