Qt android, new qml window not working properly

I have this main window:

ApplicationWindow { id : mainWindow width: 640 height: 480 visible: true Button{ text: "go back to form 1" onClicked: { form2.visible = true; } } SecondForm{ id: form2 } } 

Second window:

 Window{ id: main width: 640 height: 480 x: 0 y: 0 visible: false; Button{ text: "go back to form 1" onClicked: { main.visible = false; } } } 

The desktop version is fine, but on android, when I run the application, this behavior is strange! When I click the button in mainWindow, this error occurs: W/Qt ( 8903): (null):0 ((null)): QEGLPlatformContext::swapBuffers(): eglError: 12301, this: 0x6b46e7c0 , although it seems that the second form Called, and the main window becomes inactive. But the second window is not visible. Although I can not see the "from" and "inside" buttons. When I touch the area in which the button is supposed to be located, apparently it works and the second window leaves, then the first window is activated again. When I try to return to mainWindow by pressing the Android feedback button, it will return to mainWindow, and this warning: W/Qt ( 8903): (null):0 ((null)): Can't find surface 2 happens!

  • Could you tell me how to get Qt to display a second window?
  • According to this article , a Qt application will consist of only one action that can be launched from an Android application. Does this mean that it is not possible to have multiple windows? I mean several qml windows with only one action.
  • If it is true. Could you tell me if there is an alternative for developing an application that at least seems multivizable from the point of view of the user?
  • What do you think about deleting the entire contents of the application window and replacing it with the contents of the second window? If we add some transition, it will look like activity transitions in android. But I'm worried about performance issues.

Thanks for any help

+5
source share
1 answer

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.

+7
source

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


All Articles