我用 PyQt 制作了一个项目的原型并让它在那里工作,现在我正在尝试将它转换为 C++ 并且遇到了一些问题。
如果我不放入 Q_OBJECT 宏,它会编译并工作,但如果我将其注释掉,我会收到以下错误:
Undefined symbols:
"vtable for MapView", referenced from:
MapView::~MapView()in mapview.o
MapView::~MapView()in mapview.o
MapView::MapView(QObject*)in mapview.o
MapView::MapView()in mapview.o
"MapView::staticMetaObject", referenced from:
MapView::MapView(QObject*)in mapview.o
MapView::MapView()in mapview.o
这是标题:
#ifndef MAPVIEW_H
#define MAPVIEW_H
#include <QtGui>
#include <QObject>
class MapView : public QGraphicsScene
{
//Q_OBJECT
public:
MapView();
explicit MapView(QObject *parent = 0);
QGraphicsPixmapItem *mappixmap;
~MapView();
private:
bool dragging;
float offsetX, offsetY, downoffsetX, downoffsetY;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
};
#endif // MAPVIEW_H
第二个问题是如果我在这里省略 Q_OBJECT 宏会发生坏事吗?
是的,我知道将 QGraphicsScene 称为“视图”是愚蠢的。