1

I have an app I wrote which uses dialogs, they worked fine on a desktop windows build but cause all kinds of problems on android. I then made an ultra simple program below to try and simplify the problem. I found some code on stack overflow (here) which works but the code seems overcomplicated and unnecessary.

Clicking the first button works fine. It calls the function which is the code I pulled from the link. Clicking the second button causes the following errors:

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)

Behavior:

Dialog opens, it looks strange with odd background effects, the main window turns to all white so it doesn't look like a popup over the main window, "OK" is clickable and when clicked animates depression (not release) then the app freezes.

My Questions:

  1. What is a transient parent? I searched everywhere and never could get a clear answer.
  2. Why does the verbose and confusing dialog work while the simple one doesn't? More than anything I just want to understand what is happening.

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
    }
}

MessageDialog.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
    }
}
DisplayName
  • 239
  • 3
  • 7

0 Answers0