Skip to content

oyoungs/QAsyncTask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QAsyncTask

A tool for execute some async task and do the callback in the main thread(UI thread)

usage:

  1. include the header file qasynctask.h
  2. add library libqasync to the project, eg. -lqasync
  3. example code
#include "qasynctask.h"
#include <QApplication>
#include <thread>
#include <iostream>

int main(int argc, char **argv)
{
    QApplication a(argc, argv);
    
    QAsyncTask task;
    task.registerTaskReactor("test", [](const QAsyncTaskArgs& args) {
        QAsyncTaskResult result;
        result.success = true;
        result.message = "Success";
        result.userData = args;
        return result;
    });

    task.createTask("test", QAsyncTaskArgs{}, [](const QAsyncTaskResult& result) {
        std::cout  << (result.success ? "successful": "failed") << std::endl;
        std::cout << "callback thread: " << std::this_thread::get_id() << std::endl;
    });

    std::cout << "main thread: " << std::this_thread::get_id() << std::endl ;

    return a.exec();
}

About

基于Qt事件循环的异步任务管理

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages