28 lines
651 B
C++
28 lines
651 B
C++
#ifndef __ASYNCEVENT_H__
|
|
#define __ASYNCEVENT_H__
|
|
|
|
#include "rw_zlog.h"
|
|
#include <QCoreApplication>
|
|
#include <QEvent>
|
|
#include <functional>
|
|
|
|
class AsyncEvent : public QEvent {
|
|
public:
|
|
using Functor = std::function<void()>;
|
|
AsyncEvent(Functor &&functor)
|
|
: QEvent(static_cast<QEvent::Type>(QEvent::registerEventType())), m_functor(std::forward<Functor>(functor)) {
|
|
}
|
|
|
|
~AsyncEvent() {
|
|
if (QCoreApplication::closingDown()) {
|
|
LOGW("QCoreApplication closed,skip handle task.");
|
|
return;
|
|
}
|
|
if (m_functor) m_functor();
|
|
}
|
|
|
|
private:
|
|
Functor m_functor;
|
|
};
|
|
|
|
#endif // __ASYNCEVENT_H__
|