QML is too slow to load images

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

  • 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?

  • @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.

  • @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.


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

  • @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..

  • 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?.

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

  • @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] 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.

  • @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.

  • @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


    #include <QObject>
    #include <QNetworkAccessManager>
    class CustomNetworkAccessManager : public QNetworkAccessManager
       explicit CustomNetworkAccessManager(QObject *parent = 0);
        QNetworkReply *createRequest( Operation op, const QNetworkRequest &req, QIODevice * outgoingData=0 );


    #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;


    #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
        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;
        return app.exec();

Log in to reply

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