Perhaps it’s entirely possible that on Android you are limited to one window. This makes sense, since almost all Android applications have a single-window application, even those that are not full-screen.
This is why you get an error message trying to create a second window, it’s not a problem with forcing Qt, it is a problem with Android that doesn’t support such “interface paradigms” for desktop computers. The problem seems to be one with several visible surfaces, not so many with multiple windows, in Android there is probably a restriction for only one visible surface (therefore, the controls work even if they are not displayed - objects are in memory), you can have " off-screen "as much as you need, but you still have to do the work to compose them on a visible surface, which doesn’t make much sense in Qt for the sake of several windows - the Android function does not even support it.
You should find a way to arrange the contents of several windows in one window, either at the same time, or only at the request of the user.
you could implement some layout control to split the main window in different areas to place content from secondary windows, however in this way you can find that your work area is shrinking below acceptable, but if you need all the content on the screen at the same time, what is your the only solution, on the bright side, will be limited by the screen size, even if you use multiple windows, if they do not overlap
for content that is sometimes required, you can simply put it on different tabs or have some icons attached to show and hide this content, it will appear on top of the main window, and you can have it as full or just partially, use it, and then hide.
last but not least: you can use the stack view, QML comes with one and even supports animated transitions - you may have to do some extra work to adapt your application to work in a stop style, something what you should have done from the very beginning, the visual stack is the most commonly used approach for mobile applications, which requires opening multiple dialogs one above the other.
In this example, I changed your code to use the stack view, and returned the value from the second form to the first form to illustrate one of the ways you could do this (or you could just use the property):
ApplicationWindow { id: main width: 640 height: 480 visible: true StackView { id: stack anchors.fill: parent } Component { id: form1 Rectangle { width: 640 height: 480 color: "lightblue" function setText(text) { txt.text = text } Column { Button { text: "open form2" onClicked: stack.push(form2) } Text { id: txt text: "text has not been set yet" } } } } Component { id: form2 Rectangle { id: f2 width: 640 height: 480 color: "lightgreen" Column { TextEdit { id: txt text: "enter text here" } Button { text: "set text" onClicked: { var prev = stack.get(f2.Stack.index - 1) prev.setText(txt.text) stack.pop() } } } } } Component.onCompleted: stack.push(form1) }
Naturally, you can have forms in different qml files and without Component , I put all this at once for clarity. You can also change the default sliding animation without special.
The next time you want to create an application that works on both desktop and mobile devices, avoid features that are not available for all your goals, so you don’t have to go back and look for ways to replace them.
dtech source share