Crash on menuBar() after setMenuWidget()
-
I'm adding an option for frameless window to an application.
For this I wanted to use setMenuWidget. So in my mainWindow Ctor I'm doing :auto* titleBar = new CustomTitleBar(this); setMenuWidget(titleBar);
Now the thing is that this is an option. So somewhere down the line I have :
void MenuManager::setup(MenuItem* menuItems) const { QMenuBar* menuBar = getMainWindow()->menuBar(); QMenu* mainMenu = nullptr; if (!menuBar) { auto* ctb = dynamic_cast<CustomTitleBar*>(getMainWindow()->menuWidget()); if (ctb) { mainMenu = ctb->mainMenu(); } // Then populate either the menubar or the mainMenu... }
And the issue is that doing menuBar() crashes the application. I would have expected menuBar() to return nullptr after setMenuWidget has been used. What am I doing wrong?
-
@Paddle said in Crash on menuBar() after setMenuWidget():
I would have expected menuBar() to return nullptr after setMenuWidget has been used.
What made you think that?
-
Thanks for the reply.
Ok so menuBar creates a menubar when there is none.Please note that it still crashes. Which is bad.
Why would I think that? Because this function looks like a getter. For instance menuWidget() does exactly what I expected menuBar would do. IMO it's bad that menuBar creates a menu.
-
@Paddle said in Crash on menuBar() after setMenuWidget():
QMenuBar* menuBar = getMainWindow()->menuBar();
Use a debugger and see where it crashes. Since getMainWindow() is your own function I would guess it returns a nullptr.