There isn't anything in the code you have posted that would result in the QMainWindow's menu bar "disappearing". And there isn't anything in the code that would cause the QWidget "window" to become visible, because you don't give it a parent when you create it, nor do you call its show() method. Perhaps there is something happening in the createMenus() method that would result in this side effect.

QMainWindow already has a QMainWindow::menuBar() method, which creates and returns a menu bar for you to populate with menu items. Calling QMainWindow::setMenuBar() replaces this built-in menubar with your own.

If your createMenus() method is actually retrieving the QMainWindow menubar through a call to QMainWindow::menuBar() and returning that instance, then putting that instance into another widget as its menu bar will of course remove it from the original parent (QMainWindow). The same widget instance cannot be shared among more than one parent widget. In other words, if you're doing this:

Qt Code:
  1. QMenuBar * MainWindow::createMenus()
  2. {
  3. QMenuBar * pMB = menuBar();
  4.  
  5. // add menus to pMB
  6.  
  7. return pMB;
  8. }
To copy to clipboard, switch view to plain text mode 

then this would cause the "disappearing menu" effect you see when you add that menubar to a different widget.