How to ensure all models updated before accepting a QDialog

  • Hi,

    I have an issue with a QDialog, it has a QTableView using a custom model and if the user is editing a table field and doesn't leave the field or hit ENTER the edits are not reflected in the override of QDialog::accept() I have (called by signal/slot from "Ok" button clicked signal) until the super class QDialog::accept() is called. I don't want to call QDialog::accept() until I have validated the model contents so I appear to have a "Chicken & Egg" problem here.

    How do I make sure any active item delegate completes and the model setData method is called before I call QDialog::accept()?

    I would have though that clicking the "Ok" button would have been enough as that surely takes the focus away from the active item delegate but debug trace shows that the setData for the edited value on the underlying model is not called until QDialog::accept() is invoked.


  • Moderators

    Something like this should do the trick:

    void MyDialog::accept() {
       stuff->setFocus(); //to move focus away from the table or any delegate
       if( /* do any data validation */)
          QDialog::accept(); //call base implementation only if everything is ok

Log in to reply