Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QML is too slow to load images

QML is too slow to load images

Scheduled Pinned Locked Moved Solved Mobile and Embedded
10 Posts 3 Posters 4.1k 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.
  • C Offline
    C Offline
    chawila
    wrote on 4 Sept 2017, 15:14 last edited by chawila 9 Apr 2017, 15:15
    #1

    i need help here.
    i`m developing an app in qt quick so i programmed my models in c++(they load from the internet), then i call them in qml.
    now my problem is that, if i deleget the list. the images will take a long to load or even fail.

    average: 2/10 will load and the rest will fail.

    i tried those asynchronous things but still not helping..

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tomasz3dk
      wrote on 4 Sept 2017, 16:40 last edited by
      #2

      Did you try to load those images from hard drive? Of course for test only, maybe it's not a problem with delegate but only with download speed/ Internet connection?

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pablo J. Rogina
        wrote on 4 Sept 2017, 18:28 last edited by
        #3

        @chawila have you tried optimizing the images and/or loading process?
        Maybe this 4-part tutorial could help you regarding some potential optimizations for QML applications.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chawila
          wrote on 5 Sept 2017, 06:35 last edited by
          #4

          @tomasz3dk
          yes i did that, for development i connect to my local server, then my server side app get all necessary data from database and bring them back to the client app to delegete.
          and it works very fine.

          now the problem comes when i put the servier side app online.

          @Pablo-J-Rogina

          Let me read about that.
          then i`ll get back

          1 Reply Last reply
          0
          • C Offline
            C Offline
            chawila
            wrote on 5 Sept 2017, 07:34 last edited by
            #5

            @Pablo-J-Rogina
            eish i tried to rep my head around that...
            im not that good in Qt im still a beginner.

            but i managed to optimiz the images and still it is not workng..

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chawila
              wrote on 5 Sept 2017, 09:11 last edited by
              #6

              in my Application output i get these error for the images that hav failed:

              QML Image: Error transferring http://my-server-name/Inc/Upload/Image/526af378dd574dc8c926cef3cab4c58f.jpeg - server replied: Not Acceptable
              

              whats the meaning of that?.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Pablo J. Rogina
                wrote on 5 Sept 2017, 18:28 last edited by
                #7

                @chawila take a look at this, it looks like you may need to adjust your HTTP headers

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  chawila
                  wrote on 6 Sept 2017, 09:10 last edited by
                  #8

                  @Pablo-J-Rogina I asked my host provider to give me the server log here is it:

                  [Wed Sep 06 02:54:24 2017] [error] [client 168.167.80.164] ModSecurity: Access denied with code 406 (phase 2). Match of "beginsWith /?automatorsecretkey" against "Request_URI" required. [file "/opt/mod_security/hg_rules.conf"] [line "818"] [id "900095"] [msg "Bad UA :: Fake Mozilla Agent"] [hostname "my-server-name"] [uri "/Inc/Upload/Image/thumbnail_1bc7d06500e345b0e486e2280e23d514.jpeg"] [unique_id "Wa@psDJXkGAABGGBUo4AAACN"]
                  

                  i once had that problem, but i solved it with:

                  request.setRawHeader( "User-Agent" , "appName" );
                  

                  Now i dont know how to overcome it on images.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Pablo J. Rogina
                    wrote on 6 Sept 2017, 15:05 last edited by Pablo J. Rogina 9 Jun 2017, 15:08
                    #9

                    @chawila from the brief log fragment you posted, it looks like your ISP is refusing the request because of "bad user agent".

                    [file "/opt/mod_security/hg_rules.conf"] [line "818"] [id "900095"] [msg "Bad UA :: Fake Mozilla Agent"]

                    so you may need to check with them what appropriate user agents are, and then you'll need to set such value in the QNetworkAccessManager in use by QML
                    In order to do so, you'll need a custom QNetworkAccessManager class where you set the proper user agent value, and then you need to provide such custom QNAM to your QML engine by means of QQmlNetworkAccessManagerFactory. See this example about the concept of setting a custom QNAM for QML engine.
                    It's not that difficult I guess, but it's not straightforward as well.
                    You may also want to check this old post.

                    Upvote the answer(s) that helped you solve the issue
                    Use "Topic Tools" button to mark your post as Solved
                    Add screenshots via postimage.org
                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    1
                    • C Offline
                      C Offline
                      chawila
                      wrote on 7 Sept 2017, 10:42 last edited by
                      #10

                      @Pablo-J-Rogina Thank man.
                      I finally made it.

                      here is how i dit it.(just in case someone was following) :
                      it might not be the best way , but someone will get the idea

                      CustomNetworkAccessManager.h

                      #ifndef CUSTOMNETWORKACCESSMANAGER_H
                      #define CUSTOMNETWORKACCESSMANAGER_H
                      
                      #include <QObject>
                      #include <QNetworkAccessManager>
                      
                      class CustomNetworkAccessManager : public QNetworkAccessManager
                      {
                      
                      public:
                         explicit CustomNetworkAccessManager(QObject *parent = 0);
                      
                      protected:
                          QNetworkReply *createRequest( Operation op, const QNetworkRequest &req, QIODevice * outgoingData=0 );
                      };
                      
                      #endif // CUSTOMNETWORKACCESSMANAGER_H
                      

                      CustomNetworkAccessManager.cpp

                      #include "customnetworkaccessmanager.h"
                      
                      CustomNetworkAccessManager::CustomNetworkAccessManager(QObject *parent)
                      {
                      
                      }
                      
                      QNetworkReply *CustomNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData)
                      {
                      
                          QNetworkRequest new_req(req);
                          new_req.setRawHeader("User-Agent", "myAppName");
                      
                          QNetworkReply *reply = QNetworkAccessManager::createRequest( op, new_req, outgoingData );
                          return reply;
                      
                      }
                      
                      

                      main.cpp

                      #include <QGuiApplication>
                      #include <QQmlApplicationEngine>
                      
                      //i dnt know which one is required here
                      #include <QQmlEngine>
                      #include <QQmlNetworkAccessManagerFactory>
                      #include <QNetworkAccessManager>
                      #include <QtQuick/QQuickView>
                      
                      
                      
                      class MyNetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory
                      {
                      public:
                          virtual QNetworkAccessManager *create(QObject *parent);
                      };
                      
                      
                      QNetworkAccessManager *MyNetworkAccessManagerFactory::create(QObject *parent)
                      {
                      
                          CustomNetworkAccessManager *nam = new CustomNetworkAccessManager(parent);
                      
                          return nam;
                      }
                      
                      
                      /*
                       * ===============================================
                       * main
                       * ===============================================
                      */
                      int main(int argc, char *argv[])
                      {
                          QGuiApplication app(argc, argv);
                          QQmlApplicationEngine engine;
                          
                          MyNetworkAccessManagerFactory manager;
                      
                      
                          engine.setNetworkAccessManagerFactory(&manager);
                      
                          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
                      
                      
                          return app.exec();
                      }
                      
                      
                      1 Reply Last reply
                      1

                      4/10

                      5 Sept 2017, 06:35

                      • Login

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