我写了一个简单的信号槽。其中我的成员对象信号连接到类的插槽。我收到错误
我已经给出了下面的代码......如果我在构造函数中保留连接,那么我也会得到错误。
#ifndef COUNTER_H
#define COUNTER_H
#include <QObject>
#include <QTextEdit>
class Counter : public QObject
{
Q_OBJECT
public:
Counter()
{
m_value = 0;
}
int value() const
{
return m_value;
}
public slots:
void setValue(int value);
void callSetValue();
signals:
void valueChanged(int newValue);
private:
int m_value;
QTextEdit m_text;
};
#endif // COUNTER_H
//计数器.cpp
#include "counter.h"
void Counter::setValue(int value)
{
QObject::connect (&m_text, SIGNAL(textChanged()), this, SLOT(callSetValue()));
qDebug("setValue invoked");
if (value != m_value)
{
m_value = value;
m_text.setText("hai");
emit valueChanged(value);
qDebug("emited signal");
}
}
void callSetValue()
{
qDebug("callSetValue() invoked");
}
给我错误“对‘Counter::callSetValue()’的 undefined reference
最佳答案
在counter.cpp
的底部修改
void callSetValue()
到
void Counter::callSetValue()
关于c++ - qt中的信号槽给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22929172/