测试
#include "beacon/beacon.hpp"
#include <cstdio>
#include <thread>
class mouseEvent : public beacon::args {
public:
mouseEvent(int x, int y) : x(x), y(y) {}
int x, y;
};
class object : public beacon::sender {
public:
};
class mouseHandler : public beacon::multi_handler {
public:
};
class Button {
public:
void on_event(beacon::sender* sender, beacon::args* args) {
auto event = args->to<mouseEvent>();
printf("Mouse event at %d, %d\n", event.x, event.y);
}
};
int main(int argc, char** argv) {
mouseEvent event(10, 20);
object sender;
Button button;
mouseHandler handler;
handler.addListener<mouseEvent>(beacon::callback::bind(&Button::on_event, &button));
handler.raise(&sender, &event);
beacon::interval inter;
inter.set(1000, [](const char* msg){ puts(msg); }, "Hello, World!");
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
return 0;
}
g++ example.cpp -o test.exe
输出
Mouse event at 10, 20
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
编译错误
参考
C++ 仿QT信号槽二_c++模仿qt里面的信号与槽,做一个消息不同类消息传递-CSDN博客