我刚开始使用 QT,我知道信号/插槽的概念,但在实现它时我遇到了问题。看看我的代码:
#include "test.h"
#include <QCoreApplication>
test::test()
{
// TODO Auto-generated constructor stub
}
test::~test()
{
// TODO Auto-generated destructor stub
}
void test::fireslot(){
qDebug("the slot fired");
}
void test::dosignaling(){
QObject::connect(this,SIGNAL(callslot()),this,SLOT(fireslot()));
}
注意:我添加了 Q_OBJECT 宏并从 test.h 中的 QObject 继承
这是我的测试容器
#include "test.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//test t1();
test *t2 = new test();
t2->dosignaling();
return a.exec();
}
代码编译完美,但什么也不会发生。我不太确定我犯了哪一部分错误:-?