//智能指针,LAMBDA表达式,模板函数配合使用典型方式。
QSharedPointer<std::function<void(void)>> functor(new std::function<void(void)>);
(new Timer(this,AppConfig::IntervalTcpClient,false, [&,functor](){ //断线重连功能
QByteArray arr;
send_BaseBandDataFun(arr,*functor);
}))->start();
*functor = []{
qDebug() << "...........................................\n#####################"<<endl;
};
当中间不是定时器时,如:
QSharedPointer<std::function<void(void)>> functor(new std::function<void(void)>);
(*functor)();
*functor = []{
qDebug() << "...........................................\n#####################"<<endl;
};
就会报错,注意里面的细节含义。