我尝试过从QCustomPlot类派生,然后将一个小部件提升到那个特定的类,但是在构建它时会显示以下错误。Graphytti/myqcustomplot.cpp:2: error:对“`vtable for MyQCustomPlot”的未定义引用:-1: error: collect2: error: ld返回1退出状态
下面是myqcustomplot.h文件的内容
#ifndef MYQCUSTOMPLOT_H
#define MYQCUSTOMPLOT_H
#include "qcustomplot.h"
#include<QPoint>
class MyQCustomPlot:public QCustomPlot{
Q_OBJECT
QPoint cursor_pos;
public:
explicit MyQCustomPlot(QWidget *parent=0);
void mouseMoveEvent(QMouseEvent * event);
void paintEvent(QPaintEvent *event);
void paintCoordinate();
};
#endif // MYQCUSTOMPLOT_H下面是我的qcustomplot.cpp文件的内容
#include "myqcustomplot.h"
MyQCustomPlot::MyQCustomPlot(QWidget *parent): QCustomPlot(parent)
{
;
}
void MyQCustomPlot::mouseMoveEvent(QMouseEvent * event)
{
cursor_pos = event->pos();
replot();
QCustomPlot::mouseMoveEvent(event);
}
void MyQCustomPlot::paintEvent(QPaintEvent *event)
{
QCustomPlot::paintEvent(event);
paintCoordinate();
}
void MyQCustomPlot::paintCoordinate()
{
/*double price = getPrice(cursor_pos);
int y = yAxis->coordToPixel(price);*/
int y=0;
QPainter painter(this);
painter.drawLine(QPoint(50, y), QPoint(width(), y));
painter.drawLine(cursor_pos, QPoint(cursor_pos.x(), y));
//painter.drawText(QPoint(0, y), QString::number(price));
//painter.drawText(cursor_pos, timestamp);
}经过一些搜索,我意识到我的构造函数可能没有很好的定义,或者存在一些可能的链接问题。
我是Qt开发的新手,我希望在这个问题上得到帮助。
问题解决了,,我不知道到底是什么问题,.I删除了这两个文件,并使用QtCreator再次添加了它们。这次建房后没有问题。可能是MOC的问题,因此提出了这个问题的答案。
发布于 2016-02-21 16:46:47
每次创建Q_OBJECT类时,都应该运行qmake来生成所需的moc文件。
Build -> Run qmakehttps://stackoverflow.com/questions/35535655
复制相似问题