Qt链接器错误:“未定义对vtable的引用" [英] Qt Linker Error: "undefined reference to vtable"

查看:185
本文介绍了Qt链接器错误:“未定义对vtable的引用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的标题:

#ifndef BARELYSOCKET_H
#define BARELYSOCKET_H

#include <QObject>
//! The First Draw of the BarelySocket!

class BarelySocket: public QObject
{
    Q_OBJECT

public:
    BarelySocket();
public slots:
    void sendMessage(Message aMessage);
signals:
    void reciveMessage(Message aMessage);

private:
    //   QVector<Message> reciveMessages;
};

#endif // BARELYSOCKET_H

这是我的课程:

#include <QTGui>
#include <QObject>
#include "type.h"
#include "client.h"
#include "server.h"

#include "barelysocket.h"

BarelySocket::BarelySocket()
{
    //this->reciveMessages.clear();
    qDebug("BarelySocket::BarelySocket()");
}

void BarelySocket::sendMessage(Message aMessage)
{
}

void BarelySocket::reciveMessage(Message aMessage)
{
}

我收到链接器错误:

undefined reference to 'vtable for BarelySocket'

  • 这意味着我有一个未实现的虚拟方法.但是那里 在我的课堂上不是虚拟方法.
  • 我评论了媒介,认为这是原因,但是 错误没有消失.
  • Message是复杂的struct,但是即使使用int代替, 无法解决问题.
    • This implies that I have a virtual method not implemented. But there are no virtual methods in my class.
    • I commented out the vector thinking that it was the cause, but the error did not go away.
    • The Message is a complex struct, but even using int instead did not fix things.
    • 推荐答案

      每次将新调用添加到Q_OBJECT宏时,都需要再次运行qmake.您所指的vtable问题与此直接相关.

      Any time you add a new call to the Q_OBJECT macro, you need to run qmake again. The vtables issue you're referring to is directly related to that.

      只需运行qmake,假设代码中没有其他问题,您应该会很高兴.

      Just run qmake and you should be good to go assuming there are no other issues in your code.

      这篇关于Qt链接器错误:“未定义对vtable的引用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆