Problem with using resources and QtNetwork

  • @void MainWindow::send()
    QNetworkRequest request;
    QString testLink1 = "file:///Users/username/project/index.html";
    QString testLink2 = ":/test/index.html";
    connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(searchFinished(QNetworkReply*)));

    void MainWindow::searchFinished(QNetworkReply* reply)
    QString answer = "";
    while (reply->bytesAvailable())
    answer += reply->readAll();

  • Moderators

    And your problem is...?

  • why it doesn't read when I want to open this file from resources?
    [quote author="sierdzio" date="1366708725"]And your problem is...?[/quote]

  • Moderators

    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?

  • Moderators

    ... 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:


    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:


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.