首先,实现一个继承自QRunnable的类
#include <QRunnable>
#include "MyClass.h"
class HyAutoEmergencyTask:public QRunnable
{
public:
HyAutoEmergencyTask(QObject* dialog):QRunnable(),dialog_(dialog)
{
}
~HyAutoEmergencyTask(){}
void run()
{
bool isEmergencySuccess;
QString string;
//要运行的方法
//emegencyInfo是dialog_的槽方法 isEmergencySuccess,string是emegencyinfo方法的两个参数
QMetaObject::invokeMethod(dialog_,"emegencyInfo",Qt::QueuedConnection,Q_ARG(bool,isEmergencySuccess),Q_ARG(QString,string));
}
private:
HyCenterEmergenyHandler *centerEmergencyHander_;
HyLocalEmergenyHandler* localEmergencyHander_;
QObject* dialog_;
boost::shared_ptr<HyContext> localContext_;
};
class Myclass
{
//槽方法的声明按下面的来,实现即可
public slots:
void emegencyInfo(bool flag,const QString &string);
}