无限循环(while (true))
在5-10秒内停止工作。我使用Qt技术。这是代码:
void Worker::start() {
while (true) {
QNetworkReply* reply = manager->get(QNetworkRequest(QUrl("link")));
QEventLoop loop;
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
QJsonObject root = document.object();
QJsonValue response = root.value("response");
QJsonObject items = response.toObject().value("items").toArray().at(0).toObject();
int comments = items.value("comments").toObject().value("count").toInt();
if (comments == 0) {
qDebug() << "Comment";
QThread::sleep(3);
}
qDebug() << "END";
}
}
答案 0 :(得分:0)
引用OP评论(只是为了将其从未回答的问题列表中删除):
API对请求有限制。我最后添加了Sleep,它确实有用。