I am trying to create an application that shows a QMainWindow and multiple QWidget as additional windows. Each window's menu is slightly different. My problem is on MAC.
Basically, I have to update some actions.
Each time I create a new window, my constructor is like:

Qt Code:
  1. QMenuBar * MainWindow::createMenus( MultiEditor * thisWindow )
  2. {
  3. QMenuBar *menuBar;
  4. QMenu *menu;
  5. QMenu *submenu;
  6.  
  7. #ifdef Q_OS_MAC
  8. menuBar = new QMenuBar(0);
  9. #else
  10. menuBar = new QMenuBar();
  11. #endif
  12.  
  13. menu = new QMenu(tr("&File"), this);
  14. menu->addAction( thisWindow->action(MultiEditor::Undo) );
  15.  
  16. return menu;
  17. }
To copy to clipboard, switch view to plain text mode 


So, thisWindow is fixed in the moment I create a new window.
What happens is that, if I change focus and click on a different window, the action doesn't update (it applies to my previous window), as thisWindow has not changed with the focus.

So I was thinking of resetting the menuBar with a function updateMenuBar(menu) each time the focus changes, and I wrote this:


Qt Code:
  1. MainWindow::updateMenuBar( QMenuBar * menu )
  2. {
  3. #ifdef Q_QS_MAC
  4. this->setMenuBar(menu)
  5. #endif
  6. }
To copy to clipboard, switch view to plain text mode 

When I create the MainWindow, the this->setMenuBar(menu1) works fine and menu1 is set.
When I create additional windows, this->setMenuBar(menu2) or (menu3) or (...) are set correctly in the moment of the creation.

But when I change window, and then focus, and I call the function updateMenuBar(menu1) for example, the application crashes and I get the error:

Thread 1: EXC_BAD_ACCESS (code=1, ...) within the updateMenuBar(...) method.

Does any of you know if I can continuously re-setMenuBar? I really don't understand what is the best approach for MAC.

Kind regards,
Luca