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