конструктор(){
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(replyFinished(QNetworkReply*)));
QObject::connect(manager, QOverload<QNetworkReply*>::of(&QNetworkAccessManager::finished),
&loop, &QEventLoop::quit);
}
void MainWindow::replyFinished(QNetworkReply* reply){
if (reply->error() == QNetworkReply::NoError){
if(url.contains("test1")){
sendRequest("test/main1");
}else if(url.contains("test2")){
sendRequest("test/main2");
}else if(url.contains("test3")){
sendRequest("test/main3");
}else{
sendRequest("test/default");
changeProxy();
}
}
reply->deleteLater();
}
void MainWindow::sendRequest(const QString& url){
manager->get(QNetworkRequest(QUrl(url)));
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
loop.exec();
}
void MainWindow::onClicked(){
sendRequest("test/default");
}
конструктор(){
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(replyFinished(QNetworkReply*)));
QObject::connect(manager, QOverload<QNetworkReply*>::of(&QNetworkAccessManager::finished),
&loop, &QEventLoop::quit);
}
void MainWindow::replyFinished(QNetworkReply* reply){
if (reply->error() == QNetworkReply::NoError){
if(needProxy){
changeProxy();
sendRequest();
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
}
}
reply->deleteLater();
}
void MainWindow::onClicked(){
sendFirstRequest();
loop.exec():
}