Important: Please read the Qt Code of Conduct -

Parent window actions suspended when MessageBox is shown

  • If the title is not descriptive, let me explain further.

    I have a Qt single threaded front end application, which connects to a back end and keep sending the heart beat messages to inform that it's alive.
    The problem is when a message box is shown, it suspends the activity of the parent application, which causes to miss sending the heart beats, which ultimately results in disconnection due to heart beat miss count exceed.
    We can use the msgBox.setWindowModality(Qt::NonModal);, but the msgBox needs to be a class variable, or else it will be closed if that is a local variable. And also it violates the requirement as well as it, since it would allow the user to interact with the system if there is an error message being shown.
    What is the most efficient and convenient way of doing this?


  • Lifetime Qt Champion

    HI and welcome
    As you might know, all modal dialogs have their own message loop. ( exec() ) and
    this is the reason for application being suspended.

    So best option would be to use a thread for the heartbeat function and modal dialog to show error and
    block mainwindow interaction.

    If that is not an option, you could use FindChildren on mainwindow and set all Enabled to false when error is
    displayed and reverse when error is cleared. Not pretty/best design.

Log in to reply