Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml Image downloading error
Forum Updated to NodeBB v4.3 + New Features

Qml Image downloading error

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 4.4k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    huluyige
    wrote on last edited by
    #1

    Hi everyone,

    i use qmlapplicationviewer to view qml files for my application. of qml files, there a large number of Qml Image Elements with remote sources like:

    @Image{
    source:"http://xxx.xxx.com/home/an_image.jpg"
    }@

    it works fine on N8 with wifi, but i cant see images with 3G.

    Errors in the console

    @QML Image: Error downloading http://xxx.xxx.com/home/an_image.jpg- server replied: Forbidden@

    I tested the link in the web browser, it works fine.

    The most wired problem is that , with 3G, i can dowload files using QNetworkAccessManager. The problem seems that i didn't well configure the "QNetworkAccessManager" of qmlapplicationviewer, or there is some wrong for qml network transparency?

    Anyone has ideas?

    Thanks

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Looks like the problem is that your webserver is preventing access from external networks. Check the logs for your webserver when using 3G.

      Do you do anything special when using QNAM to download the images over 3G?

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • H Offline
        H Offline
        huluyige
        wrote on last edited by
        #3

        @ZapB , i tested it using another url, which is from another webserver. there was the same error.

        for my QNAM, i did nothing special.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          huluyige
          wrote on last edited by
          #4

          it seems the same problem...
          "another thread":http://developer.qt.nokia.com/forums/viewthread/2672/

          1 Reply Last reply
          0
          • G Offline
            G Offline
            geronimo77170
            wrote on last edited by
            #5

            Hi

            There is indeed some user agent filtering issue with operator network. To bypass this issue, you'll have to define a custom network access manager factory (subclass) and set it in the context of your declarative engine ("link":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeengine.html#setNetworkAccessManagerFactory) :

            @
            class NetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory
            {
            public:
            explicit NetworkAccessManagerFactory(QString p_userAgent = "");

            QNetworkAccessManager* create(QObject* parent)
            {
                CustomNetworkAccessManager* manager = new CustomNetworkAccessManager(__userAgent, parent);
                return manager;
            }
            

            private:
            QString __userAgent;
            };
            @

            Then you'll have to subclass QNetworkAccessManager in order to hook the creation of http request :

            @
            class CustomNetworkAccessManager : public QNetworkAccessManager
            {
            Q_OBJECT
            public:
            explicit CustomNetworkAccessManager(QString p_userAgent = "", QObject *parent = 0);

            protected:
            QNetworkReply *createRequest( Operation op, const QNetworkRequest &req, QIODevice * outgoingData=0 )
            {

                QNetworkRequest new_req(req);
                new_req.setRawHeader("User-Agent", __userAgent.toAscii());
            
                QNetworkReply *reply = QNetworkAccessManager::createRequest( op, new_req, outgoingData );
                return reply;
            }
            

            private:
            QString __userAgent;
            };
            @

            Then you can define a helper class to retrieve the same user agent as the one used by Qt webkit :

            @
            class UserAgentProvider : public QWebPage
            {
            Q_OBJECT
            public:
            explicit UserAgentProvider(QWidget *parent = 0);

            QString getUserAgent()
            {
                return userAgentForUrl(QUrl(""));
            }
            

            };
            @

            Finally you set the network access factory class in your QML context (for instance in main.cpp) :

            @
            // Set custom NetworkAccessManagerFactory object in QDeclarative context
            UserAgentProvider p;
            QString userAgent = p.getUserAgent();

            NetworkAccessManagerFactory factory(userAgent);
            viewer.engine()->setNetworkAccessManagerFactory(&factory);
            @

            Nicolas

            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