c++qtmenubarmainwindow

Qt MainWindow doesn't show MenuBar


In the code below I create Qt Widget's Application, base class QMainWindow, and without .ui form. Cant understand why MenuBar doesn't show, tried different variants and no one works.

This image demonstrate what i got

.

System Ubuntu 16.04. Using QMake version 3.0 and Qt version 5.5.1

Note: on other machines the same code works correctly.

Below mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtGui>
#include <QWidget>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();
private:
    QMenu *file;
};

#endif // MAINWINDOW_H

Below mainwindow.cpp, commented lines show how I tried to fix it.

#include "mainwindow.h"
#include <QtGui>
#include <QtWidgets>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    //QVBoxLayout *vbl = new QVBoxLayout;
    QMenu *file = new QMenu("&File"); //menuBar()->addMenu("&File");//new QMenu("&File");
    file->addAction("&Quit",qApp,SLOT(quit()),Qt::CTRL+Qt::Key_Q);


    QMenuBar *mb = menuBar();

    mb->addMenu(file);
    mb->show();
    setMenuBar(mb);

    //vbl->setMenuBar(mb);
    //setLayout(vbl);

    resize(400,400);
}

MainWindow::~MainWindow()
{

}

Solution

  • After some investigations and reinstalling of all components I solved this simple problem. Need to change in 'System Settings -> Appearance -> Behavior' parameter for 'Show the menus for a window' from the "In the menu bar" to "In the window's title bar". Thanks to everyone who tried to help.