以下是源代码
#include<qapplication.h>
#include<qpopupmenu.h>
#include<qpushbutton.h>
#include<qmenubar.h>
#include<qfont.h>
#include<qlineedit.h>
#include<qstring.h>
class MyMainWindow: public QWidget
{
public:
MyMainWindow();
private:
QPopupMenu *file;
QPopupMenu *edit;
QPopupMenu *tools;
QPopupMenu *help;
QMenuBar *menubar;
QLineEdit *ledit;
};
MyMainWindow::MyMainWindow()
{
setGeometry(100, 100, 300, 300);
file=new QPopupMenu();
file->insertItem("New");
file->insertItem("Open");
file->insertItem("Save");
file->insertItem("Print");
file->insertItem("Quit", qApp, SLOT(quit()));
edit=new QPopupMenu();
edit->insertItem("Select All", qApp, SLOT(selectAll()));
edit->insertItem("Copy");
edit->insertItem("Cut");
edit->insertItem("Past");
edit->insertItem("Delet");
tools=new QPopupMenu();
tools->insertItem("Fonts");
tools->insertItem("Pargraph");
tools->insertItem("Options");
help= new QPopupMenu();
help->insertItem("Menual List");
help->insertItem("Our WebSite");
help->insertItem("About This Program");
menubar=new QMenuBar(this);
menubar->insertItem("File", file);
menubar->insertItem("Edit", edit);
menubar->insertItem("Tools", tools);
menubar->insertItem("Help", help);
ledit =new QLineEdit(this);
ledit->setText("Input Your Word Here");
ledit->setFont(QFont("Times", 12, QFont::Bold) );
ledit->setGeometry(20, 40, 300, 60);
}
int main(int argc, char **argv)
{
QApplication a(argc, argv);
MyMainWindow w;
a.setMainWidget(&w);
w.show();
a.exec();
}
在运行了make命令后出现了一系列的错误
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/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o file.o file.cpp
file.cpp:2:23: error: qpopupmenu.h: 没有该文件或目录
file.cpp:14: 错误: ISO C++ 不允许声明无类型的‘QPopupMenu’
file.cpp:14: 错误: expected ‘;’ before ‘*’ token
file.cpp:15: 错误: ISO C++ 不允许声明无类型的‘QPopupMenu’
file.cpp:15: 错误: expected ‘;’ before ‘*’ token
file.cpp:16: 错误: ISO C++ 不允许声明无类型的‘QPopupMenu’
file.cpp:16: 错误: expected ‘;’ before ‘*’ token
file.cpp:17: 错误: ISO C++ 不允许声明无类型的‘QPopupMenu’
file.cpp:17: 错误: expected ‘;’ before ‘*’ token
file.cpp: In constructor ‘MyMainWindow::MyMainWindow()’:
file.cpp:26: 错误: ‘file’在此作用域中尚未声明
file.cpp:26: 错误: expected type-specifier before ‘QPopupMenu’
file.cpp:26: 错误: expected `;' before ‘QPopupMenu’
file.cpp:33: 错误: ‘edit’在此作用域中尚未声明
file.cpp:33: 错误: expected type-specifier before ‘QPopupMenu’
file.cpp:33: 错误: expected `;' before ‘QPopupMenu’
file.cpp:40: 错误: ‘tools’在此作用域中尚未声明
file.cpp:40: 错误: expected type-specifier before ‘QPopupMenu’
file.cpp:40: 错误: expected `;' before ‘QPopupMenu’
file.cpp:45: 错误: ‘help’在此作用域中尚未声明
file.cpp:45: 错误: expected type-specifier before ‘QPopupMenu’
file.cpp:45: 错误: expected `;' before ‘QPopupMenu’
file.cpp:51: 错误: ‘class QMenuBar’没有名为‘insertItem’的成员
file.cpp:52: 错误: ‘class QMenuBar’没有名为‘insertItem’的成员
file.cpp:53: 错误: ‘class QMenuBar’没有名为‘insertItem’的成员
file.cpp:54: 错误: ‘class QMenuBar’没有名为‘insertItem’的成员
file.cpp: In function ‘int main(int, char**)’:
file.cpp:66: 错误: ‘class QApplication’没有名为‘setMainWidget’的成员
make: *** [file.o] 错误 1
请各位大哥们帮帮忙