Using QNetworkAccessManager freezes the QML GUI
-
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 -
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.