In my project i want to download files from server. I am trying to download files using Qnetwrokaccessmanager. in my code am using a connect function like
connect(manger_, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinshed(QNetworkReply*)))
On the time execution of project does not call the function replayFinshed()
manger_= new QNetworkAccessManager(this);
connect(manger_, SIGNAL(&QNetworkAccessManager::finished), this, SLOT(replyFinshed(QNetworkReply*)));
connect(manger_, SIGNAL(QNetworkReply::error()), SLOT(errmsg(QNetworkReply *)));
QUrl url(str);
QNetworkRequest request;
request.setUrl(url);
rsult = manger_->get(request);
void Cricbang::replyFinished(QNetworkReply* reply){
QMessageBox::information(this, "replay", "finished");
if (reply->error())
{
qDebug() << "ERROR!";
qDebug() << reply->errorString();
}
else
{
QFile *file = new QFile("saved/team.json");
if (file->open(QFile::Append))
{
file->write(reply->readAll());
file->flush();
file->close();
}
delete file;
}
reply->deleteLater();
}
Try changing
connect(manger_, SIGNAL(&QNetworkAccessManager::finished), this, SLOT(replyFinshed(QNetworkReply*)));
to
connect(manger_, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinshed(QNetworkReply*)));
or use the new syntax introduced in Qt5 like eyllanesc suggested
connect(manger_, &QNetworkAccessManager::finished, this, &Cricbang::replyFinshed);
See more at https://wiki.qt.io/New_Signal_Slot_Syntax