g ++错误:在'*'标记之前预期')'

时间:2013-03-30 22:08:57

标签: c++ linux qt qt4

我有这段代码。我试过的是将QGraphicsScene子类化为重新实现它的keyPressEvent()方法。我必须选择这种特殊的实现方式(特别是typedef部分)为此,要解决与代码其他部分的兼容性问题。

keypress.h

#include <QWidget>
#include <QGraphicsScene>
#include <QGraphicsView>

class Canvas;

typedef struct{
    int id;
    int pid;
    Canvas *qgc;

}scene;

class Canvas: public QGraphicsScene {

    private:
        scene *gc;

    public:
        Canvas(Scene* gc, QWidget *parent=0);

    protected:
        void keyPressEvent(QKeyEvent *e);
};

keypress.cpp

#include <QApplication>
#include <QKeyEvent>

#include "keypress.h"

Canvas::Canvas( Scene* gc, QWidget *parent)
    : QGraphicsScene(parent)
{
    this->gc=gc;
}

void Canvas::keyPressEvent(QKeyEvent *event)
{
   if (event->key() == Qt::Key_Escape) {  
   qApp->quit();
   } 
}

的main.cpp

#include <QApplication>
#include "keypress.h"
#include <QGraphicsView>

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

  Scene *s;
  Canvas *canvas=new Canvas(s);
  canvas->addText("Hello");

  QGraphicsView view(canvas);
  view.show();
  return app.exec();
}

每当我尝试编译此程序时,我都会收到错误

In file included from keypress.cpp:4:
keypress.h:29: error: expected ‘)’ before ‘*’ token
keypress.cpp:6: error: expected ‘)’ before ‘*’ token
make: *** [keypress.o] Error 1

我的代码中有什么问题?

0 个答案:

没有答案