You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
705 B
C++

#ifndef _H_QFUNCTIONTRANSFER_H_
#define _H_QFUNCTIONTRANSFER_H_
#include <QObject>
#include <functional>
class QFunctionTransfer : public QObject
{
Q_OBJECT
public:
explicit QFunctionTransfer(QObject *parent = 0) {
qRegisterMetaType<std::tr1::function<void()>>("std::tr1::function<void()>");
connect(this, &QFunctionTransfer::comming, this, &QFunctionTransfer::exec, Qt::QueuedConnection);
};
void execInMain(std::tr1::function<void()> f) {
emit this->comming(f);
};
static QFunctionTransfer* Instance() {
static QFunctionTransfer ins;
return &ins;
}
signals:
void comming(std::tr1::function<void()> f);
public slots:
void exec(std::tr1::function<void()> f)
{
f();
};
};
#endif