qt(c++):
事件中直接写函数:
QNetworkReply *reply = manager_->get(request); connect(reply, &QIODevice::readyRead,this,[&](){ QByteArray data = reply->readAll(); DecodeReply(data); }); connect(reply, &QNetworkReply::errorOccurred, this, [&](QNetworkReply::NetworkError code){ qDebug()<<code; }); connect(reply, &QNetworkReply::sslErrors, this, [&](const QList<QSslError> &errors){ qDebug()<<errors; });
直接写一个函数来用:
auto func_countDate = [&](QString date) { int result = -1; QDate today = QDate::currentDate(); QStringList dateList = date.split("/"); if(dateList.size()!=3) { qDebug()<<"date error"; } else { result = -today.daysTo(QDate(dateList[0].toInt(),dateList[1].toInt(),dateList[2].toInt())); } return result; };
c#(.NET):
void Start() { mSocketMgr = new socket_management(); mSocketMgr.Init(); //Debug.Log("connect to server"); mSocketMgr.new_msg += msg => { string result = System.Text.Encoding.UTF8.GetString(msg); Debug.Log("get msg : "+result); }; }