C++ (Qt)#include <iostream>#include "signal_slot.h"#include <cmath> using namespace std; class A{public: ssc::signal<int, float> sig_a2; void run() const { sig_a2(4, 2.5); }}; class B : public ssc::trackable{public: B() {} double slot_b2(double x, float y) { double res = pow(x, y); cout << "slot_b2, x^y = " << res << endl; return res; }}; int main(){ ssc::signal<double, double> sig_test; B b; sig_test.connect(&b, &B::slot_b2); A a; a.sig_a2.connect(&sig_test); a.run(); return 0;}
C++ (Qt)bool connect(const ptr_base_connection &p) { int priority = p->priority(); m_iterator position = m_list.begin(); for (m_iterator it = m_list.begin(); it != m_list.end(); ++it) { if (p->is_same((*it).get())) return false; if (priority < (*it)->priority()) ++position; } m_list.insert(position, p); return true; }
C++ (Qt)bool set_connection_priority(const ptr_base_connection &p) { for (m_iterator it = m_list.begin(); it != m_list.end(); ++it) { if (p->is_same((*it).get()) && (*it)->is_valid()) { if ((*it)->priority() != p->priority()) { m_list.erase(it); connect(p); } return true; } } return false; }