# TAsyncLib **Repository Path**: pantherfuture/TAsyncLib ## Basic Information - **Project Name**: TAsyncLib - **Description**: 一个Qt的C++异步库,支持GUI任务、后台任务、定时器任务 - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2020-09-11 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## TAsyncLib 在GUI程序中,有很多耗时任务,比如文件打开、日志刷新、网络请求、图片操作等等这些不能影响GUI运行。同时有些非GUI任务中又可能需要去更新GUI界面,或者定时器需求等,TAsync将解决这些问题。 ## 使用 首先引入头文件,具体代码运行项目即可 ``` TTaskQueue::get(); /* GUI更新测试:非UI线程,同步调用GUI更新任务,普通成员函数 */ QtConcurrent::run(QThreadPool::globalInstance(),[this](){ QThread::sleep(3); TTask task = std::bind((void (Widget::*)(int, int))&Widget::resize,this,100,10); TTaskQueue::get().queueGuiTask(task,true); }); /* GUI更新测试:非UI线程,异步调用GUI更新任务,普通成员函数 */ QtConcurrent::run(QThreadPool::globalInstance(),[this](){ QThread::sleep(5); TTask task = std::bind((void (Widget::*)(int, int))&Widget::resize,this,200,200); TTaskQueue::get().queueGuiTask(task,true); }); /*GUI线程调用:GUI线程禁止同步调用!!!! */ TTask asynctask = std::bind((void (Widget::*)(int, int))&Widget::resize,this,10,100); qDebug() << TTaskQueue::get().queueGuiTask(asynctask,false); single_timer_test(); repeat_timer_test(); back_ground_task_test(); /* GUI更新测试:绑定重载函数 */ TTask task = std::bind((void (Widget::*)(int, int))&Widget::resize,this,100,100); TTaskQueue::get().queueGuiTask(task,false); ```