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. Using QNetworkAccessManager freezes the QML GUI
Qt 6.11 is out! See what's new in the release blog

Using QNetworkAccessManager freezes the QML GUI

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 667 Views 2 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.
  • J Offline
    J Offline
    James A
    wrote on last edited by
    #1

    I created simple QML Application with a single button. I clicking the button the button clicked message is printed on application output. But When I declare the QNetworkAccessManager class it completely freezes the GUI. The button does not respond to the button click events. Where as when I comment the networkmanger the GUI works fine.

    Added the code below

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QtNetwork>
    
    int main(int argc, char *argv[])
    {
    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    #endif
    
        QGuiApplication app(argc, argv);
    
    // Commenting this line removes GUI freeze
        QNetworkAccessManager manager;
    
        QQmlApplicationEngine engine;
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        engine.load(url);
    
        qDebug() << "Application ended ";
    
        return app.exec();
    }
    
    import QtQuick 2.6
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.2
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Button {
            id: button
            x: 270
            y: 195
            text: qsTr("Button")
            onClicked: {
                console.log("Button clicked")
            }
        }
    }
    
    

    Note :
    I am testing this on iMX6ULL processor which has display connected to it. And using Qt version 5.11.3

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

      Judging from code alone - this should work fine. You can check on a desktop if you are able to replicate such behaviour. I suspect it to be a quirk of your embedded board or a bug in Qt (update to newer version if possible!).

      You can move QNAM to a separate thread, then it should not interfere.

      (Z(:^

      1 Reply Last reply
      0
      • J Offline
        J Offline
        James A
        wrote on last edited by
        #3

        Hi @sierdzio ,

        In desktop it is working fine. Moving it to different thread fixed the GUI freeze issue in the device. I will continue to find out , if it is a bug in device or in Qt version.
        Thanks for the reply

        Regards,
        James A

        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