Important: Please read the Qt Code of Conduct -

Model-View and Undo

  • I am extending my app with undo functionality. It consists of a table view and a model derived from QAbstractTableModel. My model now has an undo stack as member and the commands operate on the model. If setData() is called I just push the concerning command on the stack. When first trying out undo I noticed that the view was not updated immediately, because dataChanged() was not emitted. dataChanged(..) is a protected (why?) member of QAbstractItemModel, but because I use the undo framework I need to call it from my commands within undo() / redo() and not only from the model. For now I extended my model class with a public method called UpdateView(const QModelIndex& index) which just emits dataChanged(..). UpdateView(..) can then be called from any command. This of course is not an optimal solution. Any ideas how I could improve my software design? And why is dataChanged() protected in the first place? Or should I just add my commands as friends to my model?

  • As I know: dataChanged() won't be called in this case.
    You have to call somehow manually on the model an update().

    This code maybe helps:
    (ie.: myGraphicsScene->update(); )

  • I am not soo sure if you understood my question..

Log in to reply