How to return Qmessage box output to other function



  • Hello guys,
    I have a Qmessage box with yes and no button. I want to return the output of the qmessagebox whether yes button is press or no button is pressed to another function. Can anyone will help me how to do this.
    Thanks


  • Qt Champions 2016

    Hi and welcome

    Not sure what is question is but let's say we have

    QMessageBox msgBox;
    msgBox.setText("The document has been modified.");
    msgBox.setInformativeText("Do you want to save your changes?");
    msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
    msgBox.setDefaultButton(QMessageBox::Save);
    int ret = msgBox.exec();
    Then ret has the result.

    so if you have it in a function

    int AskTheUser() {
    QMessageBox msgBox;
    ...
    int ret = msgBox.exec();
    return ret;
    }

    then somewhere else

    void someclass::somefunc() {
    int result=AskUser();
    if (result == QMessageBox::Save)
    DOIT()
    }



  • ok thanks that solved my problem


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.