本文介紹了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 的未定義引用"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!