PDA

View Full Version : Basic QMainWindow doesn't show menubar



Jeffb
14th April 2010, 11:30
Hi Guys

I've just started with QT and have created a QMainWindow in QT Designer. I've added several menuItems with actions to the menubar.
I then create a subclass (MainWindow) inheriting from Ui::MainWindow and QMainWindow.
Then in main, I create MainWindow and show it.

Compiles fine and runs but only shows the mainWindow without the menubar.

Am running Leopard on a Mac.

What might I be doing wrong?

Jeff

hollowhead
14th April 2010, 13:24
I had this problem I'm also a beginner, adding the snippet of code shown below on the constructor in the mainwindow.cpp file solved it for me.




MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this); // required so menus appear only window w/o it

wysota
14th April 2010, 13:45
Am running Leopard on a Mac.
On Macs the menu bar is on top of the screen and not in the window.

Jeffb
14th April 2010, 13:52
@Master

Of course it is.

Been reading too many textbooks that are based on Windows - I forgot what my own operating system looks like. :)

Thanks heaps
Jeff

@Novice

Originally I forgot to put in setupUi(this) and the program ran but nothing showed up including the form.
When I put it in, everything worked fine - I just didn't realise it - thanks again Master of Zen.

Jeff