iT邦幫忙

0

誰和我一樣對於使用lambda表達式已經上癮了?

  • 分享至 

  • xImage
  •  

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);
        };
    }

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言