qt - QML 对话框导致 Android 上的冻结(仅)。瞬态父级不能与窗口相同
问题描述
我有一个我编写的使用对话框的应用程序,它们在桌面窗口构建上运行良好,但在 android 上会导致各种问题。然后我在下面制作了一个超简单的程序来尝试简化问题。我发现了一些关于堆栈溢出的代码(这里),但这些代码似乎过于复杂且不必要。
单击第一个按钮可以正常工作。它调用了我从链接中提取的代码的函数。单击第二个按钮会导致以下错误:
W libTestAndroidDialog_armeabi-v7a.so: transient parent QQuickWindowQmlImpl_QML_54(0xe056e3e0) cannot be same as window
W libTestAndroidDialog_armeabi-v7a.so: (qrc:/android_rcc_bundle/qml/QtQuick/Dialogs/DefaultWindowDecoration.qml: No such file or directory)
行为:
对话框打开,奇怪的背景效果看起来很奇怪,主窗口变成全白,所以它看起来不像主窗口上的弹出窗口,“确定”是可点击的,当点击动画时按下动画(不释放)然后应用程序冻结.
我的问题:
- 什么是临时父母?我到处搜索,始终无法得到明确的答案。
- 为什么冗长且令人困惑的对话有效而简单的对话无效?最重要的是,我只想了解正在发生的事情。
main.qml:
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Window 2.12
import QtQuick.Dialogs 1.2
Window {
id: mainWindow
width: 640
height: 480
visible: true
title: qsTr("Hello World")
////////////////////////////////
// The below code works
Button {
id: buttonThatWorks
anchors.centerIn: parent
width: 150
height: 100
text: "Works"
onClicked: {
showMessageBox('Hey this actually works!');
}
}
function showMessageBox(message) {
var component = Qt.createComponent("MessageDialog.qml")
if(component.status === Component.Ready) {
var dialog = component.createObject(mainWindow)
dialog.title = qsTr("Information")
dialog.text = message
dialog.open()
} else
console.error(component.errorString())
}
/////////////////////////////////////
// The below code does not work
Button {
anchors.horizontalCenter: parent.horizontalCenter
y: buttonThatWorks.y + buttonThatWorks.height + 10
width: 150
height: 100
text: "Doesn't"
onClicked: {
bustedDialog.open()
}
}
Dialog {
id: bustedDialog
width: 150
height: 150
x: 50
y: 50
title: "dialog"
standardButtons: Dialog.Ok
}
}
消息对话框.qml
import QtQuick 2.7
import QtQuick.Controls 2.2
Dialog {
standardButtons: DialogButtonBox.Ok
property alias text : textContainer.text
Text {
id: textContainer
anchors.fill: parent
}
}
解决方案
推荐阅读
- discord.js - 如何计算有多少人在使用我的机器人?
- excel - Excel VBA - 删除特定的条件格式规则
- leaflet - 在 Leaflet 中的 WMS Tiles 之间切换
- ckeditor5 - CKEditor5 样式下拉菜单
- swift - 委托方法不会被第二次调用
- c# - 从不同目录导入 proto 文件
- javascript - 将输入搜索框和固定表头添加到 html/css/javascript 项目
- entity-framework - EF Core:IEnumerable 仅引用复合键的一部分
- java - ClassNotFoundException:Eclipse 中带有 Struts2 的 HttpServletRequest
- css - 如何让标题在同一行?