⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

QML MessageDialog and code after open()

  • Hi all, I have this scenario, that is not a problem for me right now, but it's baffle me. This is in QML

    I have a 'Window' opened from somewhere else. The main Window will receive a signal from C++ side. In the code that handle the signal, I have a MessageDialog pop up to inform user about the event that the signal is intended for. My goal is closing the opening 'Window' in this code too. But

    1. if I have the Window.close() code after the MessageDialog.open(), the close() never work.
    2. if I have the Window.close() code before the MessageDialog.open(), the close() works fine!!

    I understand that the open(), even as a modal dialog, will not stop the execution, but then it should close the 'Window' even the close() is executed after the open()!

    Can someone explain how QML behave this way?

  • Moderators

    Hi @TonyN
    As per the doc,

    If the QGuiApplication::quitOnLastWindowClosed property is true, and there are no other windows open, the application will quit.

    So in this case the MessageDialog is still open. Change its modality to Qt.NonModal and see if it works.

  • @p3c0 It indeed works. But then would the users can interact with background while the MessageBox is shown?

    (Btw, the "Window" that I opened is not the main window. It's just another pop up window. However, I learn that it's not the "Window" issue as it still does not work with the ApplicationModal option even I only put console.log() after the MessageBox.open() )

Log in to reply