Qt Linker Error: quot;undefined reference to vtablequot;(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 complexstruct
, but even usingint
instead did not fix things.
推荐答案
任何时候添加对 Q_OBJECT 宏的新调用,都需要再次运行 qmake.您所指的 vtables 问题与此直接相关.
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 的未定义引用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Qt 链接器错误:“对 vtable 的未定义引用"


基础教程推荐
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04