Qtnetworkaccessmanger 5.12的文件上传错误

时间:2018-11-20 08:44:12

标签: c++ qt qt5 qnetworkaccessmanager qnetworkreply

我正在尝试使用 QtNetworkAccessManager 将json文件上传到服务器。但是在程序执行时会出现错误,如连接关闭或未知错误。任何人都可以帮助我纠正这些错误

upload = new QNetworkAccessManager(this);
connect(upload, &QNetworkAccessManager::finished, this, &Cricbang::uploadFinished);
match_file=new QFile("saved/upcoming_match_list.json");
QFileInfo fileinfo(*match_file);
url.setUrl("http://serverIPadress/cricket/" +fileinfo.fileName() );
url.setUserName("userName");
url.setPassword("password");
url.setPort(22);
if (match_file->open(QIODevice::ReadOnly)){
    QNetworkRequest request(url);
    rsult=upload->put(request, match_file);
}

上传功能

 void Cricbang::uploadFinished(QNetworkReply* reply) {

   if (!reply->error()) {
       match_file->close();
       match_file->deleteLater();
       reply->deleteLater();
       QMessageBox::information(this, "upload", "finished");
   }
   else
   {
       QMessageBox::information(this, "error", reply->errorString());
   }
}

0 个答案:

没有答案