0

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++

4

2 に答える 2

0

QMainWindowから継承していて、 name を隠す可能性のあるフィールドを作成または継承していないことmenuBar、および実行したmoc(または実行した)ことは確かですqmakeか?

mainwindow.cppmainwindow.hmain.cppおよびmenus.pro例から変更されていないものは正常に動作するはずです。

$ cd の例/mainwindows/menus/
$ ls
main.cpp mainwindow.cpp mainwindow.h menus.pro
$ qmake
$メイク
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. -私。-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. -私。-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. -私。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. -私。-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 メニュー* moc_mainwindow.cpp
main.cpp mainwindow.cpp mainwindow.o menus.pro moc_mainwindow.o
于 2009-06-18T22:06:21.827 に答える
0

何らかの理由で、QMainWindow が正しく設定されていませんでした。これは、基本クラスのコンストラクターを呼び出すことで修正されました。

于 2009-06-19T01:49:15.670 に答える