I'm in the process of learning Qt4 and working through their tutorials.
In this tutorial:
http://doc.trolltech.com/4.5/mainwindows-menus-mainwindow-cpp.html
they have the following code:
fileMenu = menuBar()->addMenu(tr("&File"));
which causes the compiler to throw this error
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o main.o main.cpp g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o MainWindow.o MainWindow.cpp MainWindow.cpp: In member function ‘void MainWindow::createMenus()’: MainWindow.cpp:56: error: ‘((MainWindow*)this)->MainWindow::menuBar’ cannot be used as a function MainWindow.cpp:61: error: ‘((MainWindow*)this)->MainWindow::menuBar’ cannot be used as a function make: *** [MainWindow.o] Error 1
Does anyone know how I can fix this?
[Edit] Added full error Message with g++
For some reason QMainWindow was not getting setting up correctly. This was fixed by calling the base class constructor.
Are you sure you're inheriting from
QMainWindow
, you haven't created or inherited any fields which might shadow the namemenuBar
, and you've runmoc
(or hadqmake
do so for you)?The
mainwindow.cpp
,mainwindow.h
,main.cpp
, andmenus.pro
from the example, unmodified, should work fine.