# eventdispatcher **Repository Path**: saac/eventdispatcher ## Basic Information - **Project Name**: eventdispatcher - **Description**: 基于Qt的reactor模型 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2022-05-09 - **Last Updated**: 2025-02-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Qt Epoll Eventdispatcher 适用于 Qt 的基于 epoll 的事件分发机制 (Linux) ## 优势 * 快速稳定,基于 Qt 源码原生框架进行修改,稳定无Bug * 分别支持线程中的事件分发以及UI系统中的事件分发 * 支持类似于 google 浏览器将任务分类处理的设计思想,微任务、宏任务放在不同线程的事件分发器中处理 ## 依赖 * sudo apt install qtbase5-private-dev qttools5-dev-tools * Linux kernel >= 2.6.27 * glibc >= 2.9 * Qt >= 5.11 ## 编译 ``` cd src qmake make ``` ## 安装 After completing Build step run ``` sudo make install ``` 这将会把 `eventdispatcher_epoll.h` 安装到 `/usr/include`, `libeventdispatcher_epoll.a` 和 `libeventdispatcher_epoll.prl` 安装到 `/usr/lib`, `eventdispatcher_epoll.pc` 安装到 `/usr/lib/pkgconfig`. ## 用法 在头文件中包含事件分发实例,在事件创建之前进行设置,在 `main()` 函数中使用 ```c++ #include "eventdispatcher_epoll.h" int main(int argc, char** argv) { QCoreApplication::setEventDispatcher(new EventDispatcherEPoll); QCoreApplication app(argc, argv); // ... return app.exec(); } ``` 添加下面两行到 .pro 文件: ``` CONFIG += link_pkgconfig PKGCONFIG += eventdispatcher_epoll ``` 或者 ``` HEADERS += /path/to/eventdispatcher_epoll.h LIBS += -L/path/to/library -leventdispatcher_epoll ``` Qt 5 允许为线程指定自定义的事件分发器 ```c++ QThread *thr = new QThread; thr->setEventDispatcher(new EventDispatcherEPoll); ```