Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with using resources and QtNetwork

Problem with using resources and QtNetwork

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    __meow__
    wrote on last edited by
    #1

    @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;
    }@

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      And your problem is...?

      (Z(:^

      1 Reply Last reply
      0
      • _ Offline
        _ Offline
        __meow__
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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?

          (Z(:^

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            ... and testlink2 is not even a url ...

            1 Reply Last reply
            0
            • A Offline
              A Offline
              amccarthy
              wrote on last edited by
              #6

              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")@

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved