本文整理汇总了C++中QVector::lastIndexOf方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector::lastIndexOf方法的具体用法?C++ QVector::lastIndexOf怎么用?C++ QVector::lastIndexOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector
的用法示例。
在下文中一共展示了QVector::lastIndexOf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleRequest
//.........这里部分代码省略.........
teams[teamname].offence = query.value(rec.indexOf("offence")).toInt();
teams[teamname].forfeit = query.value(rec.indexOf("forfeit")).toInt();
}
}
{
QSqlQuery query(*db);
query.prepare(
" SELECT "
" services.name as servicename, "
" services.teamid, "
" teams.name as teamname, "
" services.ip, "
" services.flags, "
" services.defence, "
" services.lost, "
" services.advisers, "
" services.tries "
" FROM services "
" INNER JOIN teams ON teams.id = services.teamid "
" WHERE gameid = :gameid"
);
query.bindValue(":gameid", gameid);
bool bResult = query.exec();
if (!bResult) {
std::cerr << "[ERROR] " << query.lastError().text().toStdString() << "\n";
}
QSqlRecord rec = query.record();
int i = 0;
while (query.next()) {
i++;
QString teamname = query.value(rec.indexOf("teamname")).toString();
if (!teams.contains(teamname)) {
setErrorResponse(response, 1002, "Team did not found in this game.");
std::cerr << "[ERROR] database incorrect, team did not found in this game.\n";
return;
}
QString servicename = query.value(rec.indexOf("servicename")).toString();
if (!teams[teamname].services.contains(servicename)) {
teams[teamname].services[servicename] = ctfight_service();
}
int flags = query.value(rec.indexOf("flags")).toInt();
int defence = query.value(rec.indexOf("defence")).toInt();
int lost = query.value(rec.indexOf("lost")).toInt();
int advisers = query.value(rec.indexOf("advisers")).toInt();
int tries = query.value(rec.indexOf("tries")).toInt();
QString serviceip = query.value(rec.indexOf("ip")).toString();
teams[teamname].services[servicename].name = servicename;
teams[teamname].services[servicename].ip = serviceip;
teams[teamname].services[servicename].flags = flags;
teams[teamname].services[servicename].defence = defence;
teams[teamname].services[servicename].lost = lost;
teams[teamname].services[servicename].advisers = advisers;
teams[teamname].services[servicename].tries = tries;
teams[teamname].flags += flags;
teams[teamname].defence += defence;
teams[teamname].lost += lost;
teams[teamname].advisers += advisers;
teams[teamname].tries += tries;
// calculate score for team
teams[teamname].score =
teams[teamname].offence
+ teams[teamname].defence
+ teams[teamname].advisers
- teams[teamname].forfeit;
}
// check
if (i == 0) {
setErrorResponse(response, 1002, "Game with this id did not found.");
return;
}
// calculate places
QVector<int> places;
foreach (ctfight_team teamval, teams) {
if (!places.contains(teamval.score))
places.push_back(teamval.score);
}
qSort(places);
foreach (ctfight_team teamval, teams) {
teams[teamval.name].place = places.size() - places.lastIndexOf(teamval.score);
}
// serialize to json
QJsonObject scoreboard;
foreach (ctfight_team teamval, teams) {
scoreboard[teamval.name] = teamval.toJsonObject();
}
response["scoreboard"] = scoreboard;
}