问题描述
我需要一个信号发射器类,该类将与插槽连接。
但是遇到一些编译错误。已经尝试通过Internet进行许多修复。
基本类结构:
class emiterClass:public QObject
{
Q_OBJECT;
signals:
void testSignal();
public:
emiterClass();
~emiterClass();
void signalEmiter();
};
错误 Error showed in Image Here 也在文本中:
/usr/bin/ld: main.o: in function `emitterClass::emitSignal()':
/mnt/Data/Documents/DevP/QT/build-terminalhelp-Desktop-Debug/../terminalhelp/main.cpp:25: undefined reference to `emitterClass::testSignal()'
/usr/bin/ld: main.o: in function `main':
/mnt/Data/Documents/DevP/QT/build-terminalhelp-Desktop-Debug/../terminalhelp/main.cpp:45: undefined reference to `emitterClass::emitterClass()'
/usr/bin/ld: /mnt/Data/Documents/DevP/QT/build-terminalhelp-Desktop-Debug/../terminalhelp/main.cpp:45: undefined reference to `emitterClass::~emitterClass()'
/usr/bin/ld: /mnt/Data/Documents/DevP/QT/build-terminalhelp-Desktop-Debug/../terminalhelp/main.cpp:45: undefined reference to `emitterClass::~emitterClass()'
/usr/bin/ld: main.o: in function `responseClass::responseClass()':
/mnt/Data/Documents/DevP/QT/build-terminalhelp-Desktop-Debug/../terminalhelp/main.cpp:30: undefined reference to `vtable for responseClass'
/usr/bin/ld: main.o: in function `responseClass::~responseClass()':
/mnt/Data/Documents/DevP/QT/build-terminalhelp-Desktop-Debug/../terminalhelp/main.cpp:30: undefined reference to `vtable for responseClass'
collect2: error: ld returned 1 exit status
make: *** [Makefile:299: terminalhelp] Error 1
06:24:35: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project terminalhelp (kit: Desktop)
When executing step "Make"
我的系统:
安装版本:Qt 5.14.2
OS:Manjrao Linux
IDE:QT Creator 4.12.4
完整源代码
#include <QCoreApplication>
#include <QObject>
#include <QDebug>
#include <QtConcurrent/QtConcurrent>
class emitterClass:public QObject
{
Q_OBJECT;
signals:
void testSignal();
public:
emitterClass();
~emitterClass();
void emitSignal();
};
void emitterClass::emitSignal()
{
while(1)
{
system("sleep 1"); //Sleeps for a second
emit testSignal();
qDebug()<<"Signal Emited\n";
}
}
class responseClass:public QObject
{
Q_OBJECT
public slots:
void testSlot()
{
qDebug()<<"Signal Recieved\n";
}
};
int main(int argc,char *argv[])
{
QCoreApplication a(argc,argv);
emitterClass ec;
responseClass rc;
QObject::connect(&ec,SIGNAL(testSignal()),&rc,SLOT(testSlot()));
ec.emitSignal();
return a.exec();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)