PDA

View Full Version : MessageDialog does not work on iOS



Urthas
8th December 2016, 23:16
I have a silly little custom MessageDialog that is intended to solicit confirmation from a user before deleting DLC. Here is the code:



import QtQuick 2.5
import QtQuick.Dialogs 1.2

MessageDialog {
id: root

property string dlcName: ""

icon: StandardIcon.Information
title: qsTr("Delete content")
text: qsTr("<p>You are about to delete '" + dlcName + "'. " +
"If you wish to access this content in future, you will have to re-download it.</p>" +
"<p>Tap 'OK' when you are ready to proceed.</p>")
standardButtons: StandardButton.Cancel | StandardButton.Ok
}

And here is the calling code:


Item {
id: root

signal deletionRequested(string dlcName)

function alertDeletion(name) {
deleteDialog.dlcName = name
deleteDialog.open()
}

anchors.fill: parent

DeleteDLCDialog {
id: deleteDialog

onAccepted: root.deletionRequested(dlcName)
}

....
}

This works great on Desktop (i.e., MacOSX) and Android, but no dialog appears on iOS. Console logging shows that the alertDeletion function is called. If I change MessageDialog to FileDialog (and comment out the now-invalid properties, of course) then I see a file dialog as expected.

I found a bug about this here (https://bugreports.qt.io/browse/QTBUG-46372). But it's somewhat old, the "workaround" posted in the comments doesn't work for me, and I can't find anything else. I've tried running in debug and release mode, with no difference. Is this still an issue in others' experience? Is it solvable, and if so, how? If not, what is the recommended workaround?

I'm running Qt Creator 4.1.0, based on Qt 5.7.0 (Clang 7.0 (Apple), 64 bit).

Thank you very much!

anda_skoa
9th December 2016, 09:40
The bug report might not be applicable, I think the problem there was showing the message dialog "too soon", i.e. while the application was not fully ready yet.
My guess is your dialog is triggered via user interaction.

Have you tried a very minimal example, just some UI for the user to trigger the message dialog?

Cheers,
_

P.S.: don't concatenate runtime data into a translated string, positioning will depend on the translation. Use the arg() mechansim instead

Urthas
9th December 2016, 17:05
Have you tried a very minimal example, just some UI for the user to trigger the message dialog?

In fact, my "application" at this point is all UI, and quite minimal: a Page containing a dummy ListModel gets pushed onto a StackView; each delegate has a "Delete" Button whose onClicked handler calls the alertDeletion() function shown. There is as yet not a single line of C++ code beyond the boilerplate in main.cpp.

Thanks for the tip re: qsTr(). :)

Since posting I've tried running on a different physical device but the result was the same. I'm going to confirm that there isn't something silly happening with the MessageDialog such as a width or height of zero. Once the sanity checks are concluded, I will try exposing a subclass of QMessageBox to QML, per the supposed fallback mechanism in the documentation (http://doc.qt.io/qt-5/qml-qtquick-dialogs-messagedialog.html#details).

Any further insight is appreciated.

Urthas
9th December 2016, 21:56
Findings re: width and height as shown by console.debug() statements in my custom MessageDialog:


qml: Component.onCompleted() - visible:false
/* button press event */
qml: DeleteDLCDialog::onVisibleChanged() - visible:true
qml: height:0
qml: width:0

What's even more disturbing is that if I explicitly set the width and height, the correct values are printed but there is still no dialog in evidence! :confused:

Urthas
12th December 2016, 19:37
It turns out that this is partially a result of how the iOS plugin works, and partially a bug related to the supposed fallback mechanism. See the bug report here (https://bugreports.qt.io/browse/QTBUG-55909?jql=text%20~%20%22MessageDialog%22) (fixed for 5.7.1). Setting the modality to Qt.ApplicationModal does the trick.