I'm very new to code so I apologise if this is a simple question but I am struggling. I have a GUI program that saves user input into a vector, displays it then can be saved as a txt file. Once it has been saved, I want a QMessageBox to appear asking if the user wishes to delete the now saved vector data. The vector is named v_History.
QMessageBox msgBox;
msgBox.setText("History saved to file.");
msgBox.setInformativeText("Would you like to delete the current history?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
msgBox.setDefaultButton(QMessageBox::Discard);
msgBox.exec();
Any help or advice is greatly appreciated. Thank you
When using setStandardButtons()
, exec()
returns a value indicating which standard button was clicked, eg:
QMessageBox msgBox;
msgBox.setText("History saved to file.");
msgBox.setInformativeText("Would you like to delete the current history?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
msgBox.setDefaultButton(QMessageBox::Discard);
int ret = msgBox.exec();
if (ret == QMessageBox::Discard)
{
// delete the history as needed ...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.