本文整理汇总了C++中Download::get方法的典型用法代码示例。如果您正苦于以下问题:C++ Download::get方法的具体用法?C++ Download::get怎么用?C++ Download::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Download
的用法示例。
在下文中一共展示了Download::get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: finished
void GetMsg::finished(QNetworkReply* reply)
{
QString replyStr = QString(reply->readAll());
#if QWX_DEBUG
QFile file("getmsg.json");
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << replyStr;
file.close();
}
qDebug() << "DEBUG:" << __PRETTY_FUNCTION__;
qDebug() << "DEBUG:" << replyStr;
#endif
QJsonDocument doc = QJsonDocument::fromJson(replyStr.toUtf8());
if (!doc.isObject()) { Q_EMIT error(); return; }
QJsonObject obj = doc.object();
if (obj["AddMsgCount"].toInt() == 0)
Q_EMIT noNewMsg();
Q_FOREACH (const QJsonValue & val, obj["AddMsgList"].toArray()) {
QJsonObject msg = val.toObject();
QString fromUserNameStr = msg["FromUserName"].toString();
QString toUserNameStr = msg["ToUserName"].toString();
int createTime = msg["CreateTime"].toInt();
QString content = msg["Content"].toString();
QString msgId = msg["MsgId"].toString();
int msgType = msg["MsgType"].toInt();
if (content.contains("msg")) {
content = "";
if (msgType == 3) {
QString url = m_v2 ? WX_V2_SERVER_HOST : WX_SERVER_HOST +
WX_CGI_PATH + "webwxgetmsgimg?MsgID=" + msgId + "&skey=" +
m_skey;
QString msgImgPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/img_" + msgId + ".jpg";
Download *downLoad = new Download;
downLoad->get(url, msgImgPath, true, false);
connect(downLoad, &Download::finished, [=] {
content = "<img src=\"file://" + msgImgPath +
"\" width=\"128\" height=\"128\">";
m_handleNewMsg(msgId, content, fromUserNameStr,
toUserNameStr, time(nullptr));
downLoad->deleteLater();
});
} else if (msgType == 34) {
QString url = m_v2 ? WX_V2_SERVER_HOST : WX_SERVER_HOST +
WX_CGI_PATH + "webwxgetvoice?msgid=" + msgId + "&skey=" +
m_skey;
QString msgVoicePath = QStandardPaths::writableLocation(QStandardPaths::MusicLocation) + "/voice_" + msgId + ".mp3";
Download *downLoad = new Download;
downLoad->get(url, msgVoicePath, true, false);
connect(downLoad, &Download::finished, [=] {
content = "<a href=\"file://" + msgVoicePath + "\">" +
tr("Voice") + "</a>";
m_handleNewMsg(msgId, content, fromUserNameStr,
toUserNameStr, time(nullptr));
downLoad->deleteLater();
});
} else if (msgType == 62) {
QString url = m_v2 ? WX_V2_SERVER_HOST : WX_SERVER_HOST +
WX_CGI_PATH + "webwxgetvideo?msgid=" + msgId + "&skey=" +
m_skey;
QString msgVideoPath = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation) + "/video_" + msgId + ".mp4";
Download *downLoad = new Download;
downLoad->get(url, msgVideoPath, true, false);
connect(downLoad, &Download::finished, [=] {
content = "<a href=\"file://" + msgVideoPath + "\">" +
tr("Video") + "</a>";
m_handleNewMsg(msgId, content, fromUserNameStr,
toUserNameStr, time(nullptr));
downLoad->deleteLater();
});
} else if (msgType == 49) {
content = tr("Please view it on your phone") + " <a href=\"" +
msg["Url"].toString() + "\">" + msg["FileName"].toString() +
"</a>";
} else if (msgType == 10002) {
content = tr("Withdraw a message");
} else if (msgType == 51) {
// TODO: you are tapping on your phone ;-)
} else {
content = tr("Unsupport MsgType %1").arg(msgType);
}
}
m_handleNewMsg(msgId, content, fromUserNameStr, toUserNameStr, createTime);
}
m_syncKey.clear();
Q_FOREACH (const QJsonValue & val, obj["SyncKey"].toObject()["List"].toArray()) {
m_syncKey.append(QString::number(val.toObject()["Key"].toInt()) + "|" +
QString::number(val.toObject()["Val"].toInt()));
}
Q_EMIT syncKeyChanged();
}