Qt - QQuickView(), setSource without freezing the GUI

801 views Asked by At

being trying to solve issue for a long time, no success, QT version 5.15.0. MinGW 8.1.0, 64 bit

The issue seems to happen only when loading the map plugin in the QML file, below is a snip it of the code The call qmlView->setSource(QUrl("qrc:/maps/map.qml")); waits at least 2 seconds and the GUI then freeze. Basically the GUI thread is blocked for 2 seconds. I tried to call qmlView->setSource(QUrl("qrc:/maps/map.qml")) in a separate thread but crashed, Not too sure if the Loader QML Type would work, becasue its the same GUI thread.

I even tried the example for https://doc.qt.io/qt-5/qtlocation-mapviewer-example.html, when you change provider the main GUI also freezes

Is there any way to load the QML files where the GUI does not freeze? Thanks

    QQuickView * qmlView = new QQuickView();
    QQmlEngine * eng = qmlView->engine();
    eng->addPluginPath(qApp->applicationDirPath());
    qmlView->setSource(QUrl("qrc:/maps/map.qml"));

The QML file is

import QtQuick 2.0
import QtQuick.Window 2.0
import QtLocation 5.15
import QtPositioning 5.6


Item {
    id: item
    anchors.fill: parent

    visible: true


    Plugin {
        id: mapPlugin
        name: "osm"  // Other mapas are "osm", "mapbox"  "mapboxgl", "esri", ...
    }
    Map {
        id: map
        anchors.fill: parent
        anchors.leftMargin: -84
        anchors.topMargin: -47

        objectName: "rect"



        plugin: mapPlugin
        center {
            latitude: 52.1619403
            longitude: -7.1488692
        }
        zoomLevel: 14

    }

}


After the input from JarMan, I tried to use the QML Loader, see below, but the GUI still freezes

Loader {
    id: windowLoader
    source: "qrc:/maps/map.qml"
    focus: true
    asynchronous: true

    //property bool valid: item !== null
}
0

There are 0 answers