Problem with using resources and QtNetwork
-
@void MainWindow::send()
{
QNetworkRequest request;
QString testLink1 = "file:///Users/username/project/index.html";
QString testLink2 = ":/test/index.html";
request.setUrl(QUrl(testLink1));
//request.setUrl(QUrl(testLink2));
connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(searchFinished(QNetworkReply*)));
manager->get(request);
}void MainWindow::searchFinished(QNetworkReply* reply)
{
QString answer = "";
while (reply->bytesAvailable())
answer += reply->readAll();
qDebug()<<answer;
}@ -
And your problem is...?
-
You can use QFile for that. I don't think QNAM supports resource files. And the resource is not hosted by any kind of networking device, so why should it work?
-
... and testlink2 is not even a url ...
-
QNAM supports reading from resources, but you still need to pass it a url. As Tobias said testLink2 is not a url, you need to add the qrc scheme:
@"qrc:/test/index.html"@
It wasn't clear if testLink1 works. It looks like it is missing the drive letter (if you are on Windows?). How does your url compare to what is returned by:
@QUrl::fromLocalFile("/Users/username/project/index.html")@