我正在尝试向qthread添加一个信号,但是我收到了一些错误:
错误:未定义引用`vtable for RFDongleCommunication'
错误:未定义引用`RFDongleCommunication :: newLogger(unsigned char,unsigned char)'
这是我的头文件:
#ifndef RFDONGLECOMMUNICATION_H
#define RFDONGLECOMMUNICATION_H
#include <QThread>
#include "qextserialport.h"
#include <QtGui>
class RFDongleCommunication: public QThread
{
Q_OBJECT
public:
explicit RFDongleCommunication(QextSerialPort * port);
QextSerialPort * rfport;
QByteArray data;
signals:
void newLogger(uchar,uchar);
private:
void run();
};
#endif // RFDONGLECOMMUNICATION_H
和cpp文件
#include "rfdonglecommunication.h"
#include "QDebug"
RFDongleCommunication::RFDongleCommunication(QextSerialPort * port)
{
rfport=port;
}
void RFDongleCommunication::run()
{
while(!(rfport->bytesAvailable()));
data = rfport->readAll();
uchar id = data[1];
uchar type = data[2];
emit newLogger(id,type);
}
有人看到我做错了吗?
答案 0 :(得分:0)
让你的班级在MOC流程生成中包含的另一个.cpp和.h文件中
点击:文件 - 新文件或项目 - 文件和类 - C ++ - 新增功能 类
对'vtable 的未定义引用表示未生成moc cpp文件。
答案 1 :(得分:0)
我看到这是一个非常古老的帖子,但似乎人们仍然会问非常相似甚至完全相同的问题。我会详细说明Rudolfs Bundulis给出的答案,并希望它会有所帮助。
如果您正在使用Qt Creator并且第一次编译项目时,您没有在头文件中放置“Q_OBJECT”,那么就不会生成(qthread)cpp文件的moc cpp文件。在这种情况下,只需在头文件中放入“Q_OBJECT”后运行“全部清除”和“全部重建”将不起作用。您需要转到构建文件夹手动删除Qt生成的“Makefile”并再次运行“Rebuild All”或“Build All”,您的错误消息将消失。