A
A
amf1k2019-09-03 12:13:51
Qt
amf1k, 2019-09-03 12:13:51

How to manage windows in QML?

How can you manage different windows in QML Desktop? The bottom line is that when the application starts, the necessary resources are prepared and this is quite a long time and there is a need to show some kind of SplashScreen, after which open the main window with the application.
On the Internet, solutions for Android and a manifesto were found.
Solutions were also found with ApplicationWindow and Loader, but it still works a little wrong.
In general, what are the best practices for managing windows in QML for Desktop.

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5

ApplicationWindow{
    id: rootWindow
    width: 600
    height: 600
    visible: true
    flags: Qt.Window

    Loader {
        id: loader
        Component {
            id: waitWin
            Window {
                id: waitWindow
                width: 300
                height: 300
                flags: Qt.FramelessWindowHint | Qt.Window
                Rectangle {
                    anchors.fill: parent
                    color: "red"
                }
                Text {
                    anchors.centerIn: parent
                    text: "WAIT WINDOW"
                }
                Timer {
                    interval: 2000
                    running: true
                    repeat: false
                    onTriggered: {
                        loader.sourceComponent = mainWin
                    }
                }
            }
        }

        Component {
            id: mainWin
            Window {
                id: mainWindow
                width: 600
                height: 600
                flags: Qt.Window
                Rectangle {
                    anchors.fill: parent
                    color: "green"
                }
                Text {
                    anchors.centerIn: parent
                    text: "WAIT WINDOW"
                }
            }
        }
        sourceComponent: waitWin
    }
}

This code leads to the fact that there are 2 windows at once (ApplicationWindow and Window). Or in the loader it is necessary to change only the contents of the window?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Яков Е, 2019-09-03
@amf1k

Можно подумать над использованием стандартного сплаша и из виджетов: https://doc.qt.io/qt-5/qsplashscreen.html
Что касается окон, вариантов много, можно обойтись без этих всех заморочек с лоадерами и компонентами (если нет необходимости). Например, корневой элемент просто Item, в нём вложены два окна с противоположными значениями visible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question