Pregunta
Estoy en el proceso de aprender Qt4 y trabajar con sus tutoriales.
En este tutorial:
http://doc.trolltech.com/4.5/mainwindows -menus-mainwindow-cpp.html
tienen el siguiente código:
fileMenu = menuBar()->addMenu(tr("&File"));
que hace que el compilador arroje este 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
¿Alguien sabe cómo puedo solucionar esto?
[Editar] Mensaje de error completo agregado con g ++
Solución 2
Por alguna razón, QMainWindow no se estaba configurando correctamente. Esto se solucionó llamando al constructor de la clase base.
Otros consejos
¿Está seguro de que está heredando de QMainWindow
, no ha creado o heredado ningún campo que pueda sombrear el nombre menuBar
, y ha ejecutado moc
(¿o tenía qmake
hacerlo por usted)?
El mainwindow.cpp
, mainwindow.h
, main.cpp
y menus.pro
del ejemplo, sin modificar, debería funcionar bien.
$ cd examples/mainwindows/menus/ $ ls main.cpp mainwindow.cpp mainwindow.h menus.pro $ qmake $ make g++ -c -pipe -g -O2 -mtune=native -pipe -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. -o mainwindow.o mainwindow.cpp g++ -c -pipe -g -O2 -mtune=native -pipe -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. -o main.o main.cpp /usr/bin/moc -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. mainwindow.h -o moc_mainwindow.cpp g++ -c -pipe -g -O2 -mtune=native -pipe -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. -o moc_mainwindow.o moc_mainwindow.cpp g++ -Wl,--as-needed -Wl,--hash-style=both -o menus mainwindow.o main.o moc_mainwindow.o -L/usr/lib64/qt4 -lQtGui -L/usr/lib64 -L/usr/lib64/qt4 -L/usr/X11R6/lib64 -pthread -lpng -lfreetype -lgobject-2.0 -lSM -lICE -pthread -pthread -lXrender -lXrandr -lXinerama -lfontconfig -lXext -lX11 -lQtCore -lz -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread $ ls -F Makefile main.o mainwindow.h menus* moc_mainwindow.cpp main.cpp mainwindow.cpp mainwindow.o menus.pro moc_mainwindow.o