PDA

View Full Version : QML MessageDialog not shown correctly



DLabonte
28th February 2018, 04:03
Good evening,

I am using QT5.7.1, and the UI is defined using QML. Our application is used to control an instrument and is running in kiosk mode.

I am trying to use MessageDialog element to notify the operator when certain situations arise, such as low battery power, low disk space, ...

The MessageDialog is declared in my main.qml, and is opened when a signal (notifyOperator) is emitted by a c++ method.

I have defined a slot/function in main.qml (onNotifyOperator) to handle the signal. The two are connected in the main() function of my application (similar to the example in https://andrew-jones.com/blog/qml2-to-c-and-back-again-with-signals-and-slots/). I tried to used QML Connections element to connect the signal and slots with the following compilation error: Invalid attached object assignment. I still don't understand this one, but I want to resolve this at a later date.

I also came across a comment stating that it is absolutely mandatory to do property changes before opening the Dialog, i.e. in a closed state. If I want to change things in a MessageDialog already opened, I have to close it, change the properties and then open it again. It is not sufficient to change properties and then to close and reopen (like a "redraw"). This is what the onNotifyOperator(), open the MessageDialog() after the properties are changed.
More troubling, is the fact that I am not changing the properties for the MessageDialog and still get an incomplete display of the element.

The file main.qml contains the following declaration:


QtObject {
property real defaultSpacing: 10
property SystemPalette palette: SystemPalette { }

//
// scale factors dynamically computed
//
property double horizScaleFactor : Screen.width / 1280.0;
property double vertScaleFactor : Screen.height / 800.0;

property var splashWindow: Splash {
onTimeout:
{
console.log( "Splash timeout: ...)

...
controlWindow.visible = true
}
}

property var controlWindow: Window {
id: mainWindow
objectName: "mainWindow" // Needed for signal/slot connection

// Form https://github.com/andrewrjones/qml2-to-cpp-and-back-signals/blob/master/main.qml
// this function is our QML slot; used to open a MessageDialog to notify the operator
function notifyOperator()
{
console.log( "notifyOperator slot")
myMessageDialog.open()
}
...
}

The MessageDialog is declared as follow (part of controlWindow):


MessageDialog {
id: myMessageDialog

modality: Qt.WindowModal
icon : StandardIcon.Warning
standardButtons: StandardButton.Ok

title: qsTr( "Power Adapter Status")
text: qsTr( "Please disconnect the power adapter")

onAccepted: {
console.log( "messageDialog accepted() ")
}

Component.onCompleted: {
console.log( "messageDialog.Component.onCompleted(); visible: ", visible)
console.log( "messageDialog.Component.onCompleted(); title: ", title)
console.log( "messageDialog.Component.onCompleted(); text: ", text)
}
onVisibilityChanged: {
console.log( "messageDialog.onVisibilityChanged(); visible: ", visible)
console.log( "messageDialog.onVisibilityChanged(); title: ", title)
console.log( "messageDialog.onVisibilityChanged(); text: ", text)
}
}

The messages displayed in the Application Output tab include:


Starting U:\gitMaster\ ...

qml: messageDialog.Component.onCompleted(); visible: false
qml: messageDialog.Component.onCompleted(); title: Power Adapter Status
qml: messageDialog.Component.onCompleted(); text: Please disconnect the power adapter

...
qml: notifyOperator slot
qml: messageDialog.onVisibilityChanged(); visible: true
qml: messageDialog.onVisibilityChanged(); title: Power Adapter Status
qml: messageDialog.onVisibilityChanged(); text: Please disconnect the power adapter
The program has unexpectedly finished.


Finally, I have attached a screen capture of the MessageDialog

12780

As I pointed out, the MessageDialog is incorrect even if the title and text elements are fixed. Any suggestions?
Also, how to get rid of the question mark in the title bar?

Regards,
Daniel