我正在制作需要文件下载的程序。到目前为止,我一直使用http://www.w3schools.com/xml/note.xml等下载。因为它是直接链接到文件我没有问题。 但是如何从http://saraksti.rigassatiksme.lv/?stotele=vef&a=p.search&t=xml&day=1-5&l=lv下载。我得到的只是http://saraksti.rigassatiksme.lv/index.html
对于迟到的代码感到抱歉。这是我使用的功能。脚本是下载URL。斜线变量取决于OS。
void PValidatorPlugin::downloadScript(QString script)
{
#ifdef WIN32
QString slash = "\\";
#else
QString slash = "/";
#endif
QFileInfo fileInfo(script);
QString fileName;
if(fileInfo.fileName().isEmpty())
{
fileName = "pValidator.script";
} else {
fileName = fileInfo.fileName();
}
QFile file(QDesktopServices::storageLocation(QDesktopServices::TempLocation) + slash + fileName);
if (file.exists())
{
return;
}
QNetworkAccessManager* m_NetworkMngr = new QNetworkAccessManager(Core::ICore::instance()->mainWindow());
QUrl aUrl(script);
QNetworkReply *reply= m_NetworkMngr->get(QNetworkRequest(aUrl));
QEventLoop loop;
connect(reply, SIGNAL(finished()),&loop, SLOT(quit()));
loop.exec();
file.open(QIODevice::WriteOnly);
file.write(reply->readAll());
delete reply;
}