I’ve made my first qt window. Now I’d like to make my first dialog, using qt. I have just finished creating the dialog, which is basically made of a QDialogButtonBox, and now I’d like to connect it to the window. I have two beginner’s questions:
- How can I retrieve how the dialog was closed (ok pressed or cancel pressed) from the window.cpp, which creates a new dialog, and then calls dialog->show() ?
- Where and how to destroy the dialog pointer ?
If you use
dialog->show()then I assume it’s non-modal dialog.If you have created
QDialogButtonBoxand connected its signals withaccept()andreject()slots of your dialog as documentation shows, then your dialog will emitfinished(int)and additionallyaccepted()orrejected()signals by which you can determine how it was closed.If you need more customized behavior, then you can reimplement
closeEvent(QCloseEvent *event)or create your own singnals.If you need to delete your dialog you can use
setAttribute(Qt::WA_DeleteOnClose, true);, which will delete instance on close.