首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从QCustomPlot派生的类的构造函数

从QCustomPlot派生的类的构造函数
EN

Stack Overflow用户
提问于 2016-02-21 11:43:25
回答 1查看 167关注 0票数 1

我尝试过从QCustomPlot类派生,然后将一个小部件提升到那个特定的类,但是在构建它时会显示以下错误。Graphytti/myqcustomplot.cpp:2: error:对“`vtable for MyQCustomPlot”的未定义引用:-1: error: collect2: error: ld返回1退出状态

下面是myqcustomplot.h文件的内容

代码语言:javascript
复制
#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文件的内容

代码语言:javascript
复制
    #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的问题,因此提出了这个问题的答案。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-21 16:46:47

每次创建Q_OBJECT类时,都应该运行qmake来生成所需的moc文件。

代码语言:javascript
复制
Build -> Run qmake
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35535655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档