• 7208阅读
  • 13回复

[提问]本人新学菜虫,求帮助 [复制链接]

上一主题 下一主题
离线yrb2013
 
只看楼主 倒序阅读 楼主  发表于: 2012-05-23
前两天才开始弄QT,球也不会啊!好不容易编了个,弄不清是哪里错了,诚信求教

要求:制作一个窗体,有标题栏,菜单栏,工具栏,状态栏;
      菜单栏和状态栏分别是:add、delete、modify、search四个选项
      要求指定菜单项时,状态栏有相应的显示

代码如下:mainwindow.h


离线yrb2013
只看该作者 1楼 发表于: 2012-05-23

#include <qapplication.h>
#include <qmainwindow.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <qtoolbar.h>
#include <qaction.h>
#include <qstatusbar.h>
class mainWindow : public QMainWindow
{
Q_OBJECT

public:
  mainWindow(QWidget* parent=0,const char* name=0);
  ~mainWindow();

  QMenuBar* menubar;
  QPopupMenu* fileMenu;
  QAction* fileAdd;
  QAction* fileDel;
  QAction* fileModify;
  QAction* fileSearch;
  
  QToolBar* toolBar;
  
  QStatusBar* status;
  
private slots:
  void add();
  void del();
  void modify();
  void search();
  
};
离线yrb2013
只看该作者 2楼 发表于: 2012-05-23
mainWindow.cpp

#include "mainwindow.h"
mainWindow::mainWindow(Qwidget* parent,const char* name):QMainWindow(parent,name)
{

menubar = new QMenuBar(this);
fileMenu = new QPopupMenu(this);
menubar->insertItem( "&file", fileMenu );

fileAdd = new QAction("add","&Add",CTRL+KEY_A,this);
fileDel = new QAction("delete","&Delete",CTRL+KEY_D,this);
fileModify = new QAction("modify","&Modify",CTRL+KEY_M,this);
fileSearch = new QAction("search","&Search",CTRL+KEY_S,this);

fileAdd->addTo(fileMenu);
fileDel->addTo(fileMenu);
fileModify->addTO(fileMenu);
fileModify->addTo(fileMenu);

toolBar = new QToolBar(this);

fileAdd->addTo(toolBar);
fileDel->addTo(toolBar);
fileModify->addTo(toolBar);
fileSearch->addTo(toolBar);
status = new QStatusBar(this);

fileAdd->setStatusTip("yangruibo");
fileDelete->setStatusTip("0921010121");
fileModify->setStatusTip("yangruibo");
fileSearch->setStatusTip("0921010121");
}
MainWindow::~MainWindow()
{
}
离线yrb2013
只看该作者 3楼 发表于: 2012-05-23
mian.cpp

#include <qapplication.h>
#include "mainwindow.h"

int main(int argc, char *argv[]){
QApplication app(argc,argv);

mainWindow w ;

//设置窗口的尺寸
w.resize(700,600);
//设置窗口标题栏文字
//w.setWindowTitle(QObject::tr("0921010121yrb"));
w.show();

return app.exec();
}
离线yrb2013
只看该作者 4楼 发表于: 2012-05-23
用得是QT3,老师要求,诚心求助,谢谢大家

main.cpp中添加标题栏的一列已经注释了,下面是问题:
In file included from main.cpp:2:
mainwindow.h:41:21: warning: no newline at end of file
main.cpp:18:2: warning: no newline at end of file
g++ -c -pipe -Wall -W -O2 -march=i386 -mcpu=i686 -g -DGLX_GLXEXT_LEGACY -fno-use-cxa-atexit -fno-exceptions  -DQT_NO_DEBUG -I/usr/lib/qt-3.1/mkspecs/default -I. -I. -I/usr/lib/qt-3.1/include -o mainWindow.o mainWindow.cpp
In file included from mainWindow.cpp:1:
mainwindow.h:41:21: warning: no newline at end of file
mainWindow.cpp:3: parse error before `*' token
mainWindow.cpp:7: ISO C++ forbids declaration of `fileMenu' with no type
mainWindow.cpp:7: invalid use of `this' at top level
mainWindow.cpp:8: syntax error before `->' token
mainWindow.cpp:10: ISO C++ forbids declaration of `fileAdd' with no type
mainWindow.cpp:10: `KEY_A' was not declared in this scope
mainWindow.cpp:10: invalid use of `this' at top level
mainWindow.cpp:11: ISO C++ forbids declaration of `fileDel' with no type
mainWindow.cpp:11: `KEY_D' was not declared in this scope
mainWindow.cpp:11: invalid use of `this' at top level
mainWindow.cpp:12: ISO C++ forbids declaration of `fileModify' with no type
mainWindow.cpp:12: `KEY_M' was not declared in this scope
mainWindow.cpp:12: invalid use of `this' at top level
mainWindow.cpp:13: ISO C++ forbids declaration of `fileSearch' with no type
mainWindow.cpp:13: `KEY_S' was not declared in this scope
mainWindow.cpp:13: invalid use of `this' at top level
mainWindow.cpp:15: syntax error before `->' token
mainWindow.cpp:16: syntax error before `->' token
mainWindow.cpp:17: syntax error before `->' token
mainWindow.cpp:18: syntax error before `->' token
mainWindow.cpp:20: ISO C++ forbids declaration of `toolBar' with no type
mainWindow.cpp:20: invalid use of `this' at top level
mainWindow.cpp:22: syntax error before `->' token
mainWindow.cpp:23: syntax error before `->' token
mainWindow.cpp:24: syntax error before `->' token
mainWindow.cpp:25: syntax error before `->' token
mainWindow.cpp:27: ISO C++ forbids declaration of `status' with no type
mainWindow.cpp:27: invalid use of `this' at top level
mainWindow.cpp:29: syntax error before `->' token
mainWindow.cpp:30: syntax error before `->' token
mainWindow.cpp:31: syntax error before `->' token
mainWindow.cpp:32: syntax error before `->' token
mainWindow.cpp:35: syntax error before `::' token
make: *** [mainWindow.o] Error 1
离线roywillow

只看该作者 5楼 发表于: 2012-05-23
我觉得才“前两天”开始学用Qt就写这么复杂的东西,难度过大啊……
另外说说是什么地方的问题,看全部的代码太麻烦了
专业维修核潜艇,回收二手航母、二手航天飞机,大修核反应堆,拆洗导弹发动机更换机油,无人侦察机手动挡改自动,航天飞机保养换三滤,飞碟外太空年检 ,各型号导弹加装迎宾踏板,高空作业擦洗卫星表面除尘、打蜡及抛光,东风全系列巡航导弹。并提供原子对撞机。量大从优,有正规发票。
离线yrb2013
只看该作者 6楼 发表于: 2012-05-23
回 5楼(roywillow) 的帖子
就是第四页显示的,说实话,这是大作业,没办法啊
离线yrb2013
只看该作者 7楼 发表于: 2012-05-23
高手都去哪了?灌水的就算了,真没兴趣玩儿
离线jdwx

只看该作者 8楼 发表于: 2012-05-23
建议找本书看看,着急时想起来让别人帮忙了。
这样的例子,Qt自带了很多,自己慢慢琢磨吧。
发帖时要说明:操作系统、Qt版本、编译器,这样能更快的得到回复。
离线yrb2013
只看该作者 9楼 发表于: 2012-05-23
能分析分析问题吗?别扯这有的没的
离线roywillow

只看该作者 10楼 发表于: 2012-05-23
从这一行
mainWindow::mainWindow(Qwidget* parent,const char* name):QMainWindow(parent,name)
和这一行
MainWindow::~MainWindow()
来看
大小写错误
专业维修核潜艇,回收二手航母、二手航天飞机,大修核反应堆,拆洗导弹发动机更换机油,无人侦察机手动挡改自动,航天飞机保养换三滤,飞碟外太空年检 ,各型号导弹加装迎宾踏板,高空作业擦洗卫星表面除尘、打蜡及抛光,东风全系列巡航导弹。并提供原子对撞机。量大从优,有正规发票。
离线yrb2013
只看该作者 11楼 发表于: 2012-05-23
回 10楼(roywillow) 的帖子
谢谢啊,我修改一下试试
离线tangxunmin

只看该作者 12楼 发表于: 2012-05-25
fileModify->addTO(fileMenu);
这一行写的也有问题!
离线sjyzhxw
只看该作者 13楼 发表于: 2012-05-25
回 楼主(yrb2013) 的帖子
只要窗体不要功能的话其实还好。。
快速回复
限100 字节
 
上一个 下一个