Qt_Signal_Slot - 8BitsCoding/RobotMentor GitHub Wiki
์ ์ฒด ๊ตฌ์กฐ๊ฐ ์ด๋ฐ์
QObject::connect(์๊ทธ๋, ์ฌ๋ฟ);์๊ทธ๋์ ๋ณด๋ด๋ ์ชฝ
์ฌ๋ฟ์ ๋ฐ๋ ์ชฝ์ด๋ผ ์๊ฐํ์.
์๋ฅผ ๋ค์ด ์ค๋ช
QObject::connect(&a, SIGNAL(valueChanged(int)), &b, SLOT(setValue(int)));QObject::connect(&qnode, SIGNAL(updatePCService(int)), this, SLOT(update_VS_Edit(int)));
// qnode๋ผ๋ ํด๋์ค์ updatePCService ์๊ทธ๋ ๋ฑ๋ก
// ๋ณธ(this) ํด๋์ค์ update_VS_Edit ์ฌ๋ฟ ๋ฑ๋ก// signal์ ์๋์ ๊ฐ์ด ์ฌ์ฉ๋จ.
void QNode::topic_VDS_callback(const asv_msgs::OutboardThrottleFeedback &msg)
{
for(std::vector<asv_msgs::OutboardThrottle>::const_iterator it = msg.outboard_throttles.begin(); it != msg.outboard_throttles.end(); ++it)
{
temp_VDS = *it;
}
// ์ฌ๊ธฐ
Q_EMIT updateVDS(&temp_VDS);
}// *.h ํ์ผ์์ ์๊ทธ๋์ ์๋์ ๊ฐ์ด ๋ฑ๋ก
Q_SIGNALS:
void updateVDS(asv_msgs::OutboardThrottle*);// *.h ํ์ผ์์ ์ฌ๋ฟ๋ ์๋์ ๊ฐ์ด ๋ฑ๋ก
public Q_SLOTS:
void update_VDS_Edit(asv_msgs::OutboardThrottle* msg);class Counter
{
public:
Counter() { m_value = 0; }
int value() const { return m_value; }
void setValue(int value);
private:
int m_value;
};#include <QObject>
class Counter : public QObject
{
Q_OBJECT
public:
Counter() { m_value = 0; }
int value() const { return m_value; }
public slots:
void setValue(int value);
signals:
void valueChanged(int newValue);
private:
int m_value;
}void Counter::setValue(int value)
{
if(value != m_value) {
m_value = value;
emit valueChaneged(value);
}
}Counter a, b;
QObject::connect(&a, SIGNAL(valueChanged(int)), &b, SLOT(setValue(int)));