Important: Please read the Qt Code of Conduct -

QTableView inside a QDialog

  • I have a QTableView inside a dialog and a custom model attached to the view. The model changes my data when the user edits the table; however if the dialog is rejected (cancel button) I would like to restore my original data before the edits. Is there a way the model can handle that, or do I have to make a copy of my data before launching the dialog and restore it after the dialog closes?

  • It's possible to hold the "new" data in a seperate list (via model->setData) and when the dialog is closed add an extra function that validates and replaces/adds the new data to your model. Not a problem there. No idea what kind of data you have though.
    An other option might be to "copy" your original data into a new model, set the view to that model, let it all change what is needed and when the dialog is closed, check if there are any differences between the models.

  • The data set is fairly small; I think I will go with keeping a local copy in the model and add a function to the model that will "pushData" outside. I can call this when the dialog is accepted.
    Thank you

Log in to reply