How to interrupt component loading in Loader?

I have an object Loaderthat loads very high level components. Some event arrives in the middle of the load, which requires loading to stop and return to empty Loader. Is it possible?

+4
source share
2 answers

Creating an Interrupt Object

As described in Qt, there are three methods for uploading / interrupting object creation:

Asynchronous behavior

, Loader.asynchronous true, GUI . QQmlIncubationController QQmlEngine , . Loader.asynchronous . , QQmlApplicationEngine , QQuickWindow.

Qt (Qt 5.8.0, 5.9.0 beta) ( , , derM), .

+6

, , , , , , ? , : , , .

main.qml

import QtQuick 2.7
import QtQuick.Controls 2.0

ApplicationWindow {
    id: root
    visible: true
    width: 400; height: 450

    Button {
        text: (complexLoader.active ? 'Loading' : 'Unloading')
        onClicked: complexLoader.active = !complexLoader.active
    }

    Loader {
        id: complexLoader
        y: 50
        width: 400
        height: 400
        source: 'ComplexComponent.qml'
        asynchronous: true
        active: false
        // visible: status === 1
    }

    BusyIndicator {
        anchors.fill: complexLoader
        running: complexLoader.status === 2
        visible: running
    }
}

ComplexComponent.qml

import QtQuick 2.0

Rectangle {
    id: root
    width: 400
    height: 400
    Grid {
        id: grid
        anchors.fill: parent
        rows: 50
        columns: 50
        Repeater {
            model: parent.rows * parent.columns
            delegate: Rectangle {
                width: root.width / grid.columns
                height: root.height / grid.rows
                color: Qt.rgba(Math.random(index),
                               Math.random(index),
                               Math.random(index),
                               Math.random(index))
            }
        }
    }
}
+2

Source: https://habr.com/ru/post/1674666/


All Articles