In QtQuick 2, with QtQuick controls, you can create complex desktop applications. However, it seems to me that the whole user interface should be declared and create everything at once at the beginning of the application. Any parts that you do not want to use yet (for example, the File-> Open dialog) should be created, but they are hidden, for example:
ApplicationWindow { FileDialog { id: fileOpenDialog visible: false // ... } FileDialog { id: fileSaveDialog visible: false // ... } // And so on for every window in your app and every piece of UI.
Now this may be good for simple applications, but for complex applications or applications with many dialogs, is this certainly a crazy thing? In the traditional QtWidgets model, you dynamically create your own dialogue when necessary.
I know there are some workarounds for this, for example. you can use Loader or even create QML objects dynamically directly in javascript, but they are very ugly and you lose all the benefits of the pretty QML syntax. Also you cannot "unload" components. Well Loader claims you can, but I tried and my app crashed.
Is there an elegant solution to this problem? Or do I just need to bite the bullet and create the entire potential user interface for my application right away, and then hide most of it?
Note: this page contains information on using Loader to get around this, but as you can see, this is not a very nice solution.
Edit 1 - Why a Suboptimal Bootloader?
Well, to show you why Loader is actually not so nice, consider this example, which launches a complex task and awaits the result. Suppose that - unlike all the trivial examples that people usually give - a task has many inputs and several outputs.
This is the Loader solution:
Window { Loader { id: task source: "ComplexTask.qml" active: false } TextField { id: input1 } TextField { id: output1 } Button { text: "Begin complex task" onClicked: {
If I did this without Loader , I could have something like this:
Window { ComplexTask { id: task taskInput1: input1.text componentLoaded: false onCompleted: componentLoaded = false } TextField { id: input1 } TextField { id: output1 text: task.taskOutput1 } Button { text: "Begin complex task" onClicked: task.componentLoaded = true } }
This is obviously simpler. What I explicitly want is the incorrect way to load ComplexTask and activate all of its declarative relationships when componentLoaded set to true, and then disconnect the relations and unload the component if componentLoaded set to false. I am sure there is no way to do something like this in Qt right now.