Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Model-View and Undo
Forum Update on Monday, May 27th 2025

Model-View and Undo

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jc-denton
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      broadpeak
      wrote on last edited by
      #2

      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:
      http://doc.qt.nokia.com/4.7-snapshot/tools-undoframework.html
      (ie.: myGraphicsScene->update(); )

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jc-denton
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved