0
我在閱讀在線文件時遇到了一些問題。我試圖在它被下載到一個臨時文件後讀取文件中的內容。這裏是我的代碼:Qt使用QNetworkReply獲取網絡請求,將數據下載到臨時文件
void MainWindow::fileIsReady(QNetworkReply * reply)
{
QTemporaryFile tmpFile;
tmpFile.write(reply->readAll());
QByteArray asdf = reply->readAll();
qDebug() (QString("%1").arg(asdf.length())); // returns 0
if (tmpFile.open())
{
qDebug << "attempting to read file";
QTextStream stream(&tmpFile);
QString value = stream.readAll();
qDebug << value; // value is returning nothing
}
else
{
qDebug() << "failed to open internet file";
}
}
// in MainWindow constructor (MainWindow::MainWindow)...
QNetworkAccessManager * manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(fileIsReady(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("https://www.website.com/stuff/file.exe.md5")));
我打算用它來比較兩個md5字符串。
是的,我只是想通了。我會發布我的解決方案。 –