| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 5 | |
I have 2 QMenuBars that I need to alternate between in a QMainWindow. When I set the first one, everything is fine. When I set the second one, everything is fine. When I set the first one again... CRASH! Apparently, there is no way to keep the first menu bar around. QMainWindow delete it out from under me. And there is no Copy constructor in QMenuBar to make a copy for QMainWindow. Does anyone know a way to get around this without having to recreate the menu bar each time? Keith **Please do not reply to me, reply to the list.**
Keith Esau wrote: > I have 2 QMenuBars that I need to alternate between in a QMainWindow. > > When I set the first one, everything is fine. > > When I set the second one, everything is fine. > > When I set the first one again... CRASH! > > Apparently, there is no way to keep the first menu bar around. > QMainWindow delete it out from under me. And there is no Copy > constructor in QMenuBar to make a copy for QMainWindow. > > Does anyone know a way to get around this without having to recreate > the menu bar each time? > > Keith > **Please do not reply to me, reply to the list.** QMainWindow takes ownership of the QMenuBar when you call QMainWindow->setMenuBar() and so handles the deletion of the pointer at that point. When you call setMenuBar() again, there is no expectation of anyone else handling the memory (since the QMainWindow took control) so it deletes the old bar before taking over the new one. I think you'll just have to recreate the menu bar each time (unless your menus are similar enough that you can get away with some sort of show/hide scheme). Stuart
Attachment:
Attachment:
signature.asc
Description: OpenPGP digital signature
Message 3 in thread
On Tuesday 19 June 2007 21:56, Stuart Childs wrote:
> Keith Esau wrote:
> > I have 2 QMenuBars that I need to alternate between in a QMainWindow.
> >
> > When I set the first one, everything is fine.
> >
> > When I set the second one, everything is fine.
> >
> > When I set the first one again... CRASH!
> >
> > Apparently, there is no way to keep the first menu bar around.
> > QMainWindow delete it out from under me. And there is no Copy
> > constructor in QMenuBar to make a copy for QMainWindow.
> >
> > Does anyone know a way to get around this without having to recreate
> > the menu bar each time?
> >
> > Keith
> > **Please do not reply to me, reply to the list.**
>
> QMainWindow takes ownership of the QMenuBar when you call
> QMainWindow->setMenuBar() and so handles the deletion of the pointer at
> that point. When you call setMenuBar() again, there is no expectation
> of anyone else handling the memory (since the QMainWindow took control)
> so it deletes the old bar before taking over the new one.
>
> I think you'll just have to recreate the menu bar each time (unless your
> menus are similar enough that you can get away with some sort of
> show/hide scheme).
Yes. Or you use a show/hide scheme on the menu bar itself. Put all your menus
in one menubar, and use setVisible() on the menu's menuAction() to show/hide
the menu bar entries.
Matthias
--
[ signature omitted ]