QNetworkaccessmanager 对象连接函数不调用
QNetworkaccessmanager object connect function dose not calling
在我的项目中,我想从服务器下载文件。我正在尝试使用 Qnetwrokaccessmanager 下载文件。在我的代码中,我使用了一个连接函数,比如
connect(manger_, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinshed(QNetworkReply*)))
关于项目执行时没有调用函数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();
}
尝试改变
connect(manger_, SIGNAL(&QNetworkAccessManager::finished), this, SLOT(replyFinshed(QNetworkReply*)));
到
connect(manger_, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinshed(QNetworkReply*)));
或使用 Qt5 中引入的新语法,如 eyllanesc 建议
connect(manger_, &QNetworkAccessManager::finished, this, &Cricbang::replyFinshed);
查看更多
在我的项目中,我想从服务器下载文件。我正在尝试使用 Qnetwrokaccessmanager 下载文件。在我的代码中,我使用了一个连接函数,比如
connect(manger_, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinshed(QNetworkReply*)))
关于项目执行时没有调用函数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();
}
尝试改变
connect(manger_, SIGNAL(&QNetworkAccessManager::finished), this, SLOT(replyFinshed(QNetworkReply*)));
到
connect(manger_, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinshed(QNetworkReply*)));
或使用 Qt5 中引入的新语法,如 eyllanesc 建议
connect(manger_, &QNetworkAccessManager::finished, this, &Cricbang::replyFinshed);
查看更多