C++ - Get latest release of a GitHub project

。_饼干妹妹 提交于 2021-01-29 07:18:53

问题


I have a program that uses a set of files stored in a GitHub project.

I would like to check the latest release version of that GitHub project and download those files if it's newer than local.

Does anyone know how to check release version and download from (using QT C++)?

My program is done in Qt 5 (https://github.com/bq/QssWeb2Board)


回答1:


Checking the commented lib and doing some digging around I found an answer. Here it is the main code. Thanks.

QUrl url("https://api.github.com/repos/" + owner +"/" + project + "/tags");
qInfo() << url.toString();
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QNetworkAccessManager nam;
QNetworkReply * reply = nam.get(request);

timeout=false;
timer->start(5000);

while(!timeout){
    qApp->processEvents();
    if(reply->isFinished()) break;
}

if(reply->isFinished()){
    QByteArray response_data = reply->readAll();
    QJsonDocument json = QJsonDocument::fromJson(response_data);
    return json[0]["name"].toString();
}else{
    return QString("Timeout");
}


来源:https://stackoverflow.com/questions/50540184/c-get-latest-release-of-a-github-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!