Необходимо добавить виджет menuBar в готовую программу.  Виджет отлично добавляется в MainWindow. Но необходимо сделать так, чтобы логика добавления меню была в отдельном файле. Делаю так:
topMenu.h :
#ifndef TOPMENU_H
#define TOPMENU_H
#include <QMainWindow>
#include <QApplication>
class topMenu : public QWidget {
    Q_OBJECT
public:
    topMenu(QWidget *parent = nullptr);
    void showTopMenu();
};
#endif // TOPMENU_H
topMenu.cpp:
#include "topmenu.h"
#include <QMenu>
#include <QMenuBar>
topMenu::topMenu(QWidget *parent) : QWidget(parent) {
    void showTopMenu();
}
void topMenu::showTopMenu() {
    QAction *newProject = new QAction("&Новый проект");
    QMenu *file;
    QMenuBar *menu;
    file = menu->addMenu("&Меню");
    file->addAction(newProject);
}
mainwindow.h :
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "topmenu.h"
#include <QMainWindow>
class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    topMenu *mmMenu;
};
#endif // MAINWINDOW_H
 
main.cpp:
#include "mainwindow.h"
#include "topmenu.h"
#include <QApplication>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    topMenu mmMenu;
    mmMenu.showTopMenu();
    w.show();
    return a.exec();
}
Соответственно результат нулевой, ошибок нет, но и меню не показывает...