1.这是我要编译的程序:
#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();
}
2.当我编译时候,执行qmake -project,然后qmake,然后make的时候,就出现以下的错误:
hmily@xtu:~/文档/24hours_leaar_qt/mainwindow$ qmake -project
hmily@xtu:~/文档/24hours_leaar_qt/mainwindow$ qmake
hmily@xtu:~/文档/24hours_leaar_qt/mainwindow$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.7.2/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.7.2/include/QtCore -I/usr/local/Trolltech/Qt-4.7.2/include/QtGui -I/usr/local/Trolltech/Qt-4.7.2/include -I. -I. -o mainwindow.o mainwindow.cpp
mainwindow.cpp:2:23: error: qpopupmenu.h: 没有那个文件或目录
mainwindow.cpp:14: error: ISO C++ forbids declaration of ‘QPopupMenu’ with no type
mainwindow.cpp:14: error: expected ‘;’ before ‘*’ token
mainwindow.cpp:15: error: ISO C++ forbids declaration of ‘QPopupMenu’ with no type
mainwindow.cpp:15: error: expected ‘;’ before ‘*’ token
mainwindow.cpp:16: error: ISO C++ forbids declaration of ‘QPopupMenu’ with no type
mainwindow.cpp:16: error: expected ‘;’ before ‘*’ token
mainwindow.cpp:17: error: ISO C++ forbids declaration of ‘QPopupMenu’ with no type
mainwindow.cpp:17: error: expected ‘;’ before ‘*’ token
mainwindow.cpp: In constructor ‘MyMainWindow::MyMainWindow()’:
mainwindow.cpp:26: error: ‘file’ was not declared in this scope
mainwindow.cpp:26: error: expected type-specifier before ‘QPopupMenu’
mainwindow.cpp:26: error: expected ‘;’ before ‘QPopupMenu’
mainwindow.cpp:33: error: ‘edit’ was not declared in this scope
mainwindow.cpp:33: error: expected type-specifier before ‘QPopupMenu’
mainwindow.cpp:33: error: expected ‘;’ before ‘QPopupMenu’
mainwindow.cpp:40: error: ‘tools’ was not declared in this scope
mainwindow.cpp:40: error: expected type-specifier before ‘QPopupMenu’
mainwindow.cpp:40: error: expected ‘;’ before ‘QPopupMenu’
mainwindow.cpp:45: error: ‘help’ was not declared in this scope
mainwindow.cpp:45: error: expected type-specifier before ‘QPopupMenu’
mainwindow.cpp:45: error: expected ‘;’ before ‘QPopupMenu’
mainwindow.cpp:51: error: ‘class QMenuBar’ has no member named ‘insertItem’
mainwindow.cpp:52: error: ‘class QMenuBar’ has no member named ‘insertItem’
mainwindow.cpp:53: error: ‘class QMenuBar’ has no member named ‘insertItem’
mainwindow.cpp:54: error: ‘class QMenuBar’ has no member named ‘insertItem’
mainwindow.cpp: In function ‘int main(int, char**)’:
mainwindow.cpp:66: error: ‘class QApplication’ has no member named ‘setMainWidget’
make: *** [mainwindow.o] 错误 1
这个东西老是报错,我真的就不明白了,同样是Qt4版本的,为什么我的出现这么多的问题,我解决不了了,由于我是初学者,很多的问题我可能说不到点上,还请各位大侠谅解,帮帮忙,帮我解决这个问题....
非常感谢...非常感谢...非常感谢...非常感谢...非常感谢...非常感谢...非常感谢...非常感谢...