Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTableView item update: when underlying model is effectively updated ?



  • I see that in my application (Windows as OS, QT 5.15) the QStandardItemModel :: dataChanged event is raised only if I complete the cell editing with a "return" or by clicking with the mouse on another cell of the QTableView. If I go directly to the menu of my application, the QAction method is executed first and then the method connected to the dataChanged is called. Is it possible to modify this behavior by setting a property of the QTableView or by forcing the cell's updated status in the method called by the QAction?



  • @Andrea_Benetton said in QTableView item update: when underlying model is effectively updated ?:

    If I go directly to the menu of my application, the QAction method is executed first and then the method connected to the dataChanged is called

    I guess this is possible, but slightly surprised, though I take your word.

    So you just want the dataChanged signal, which comes at the end of editing, to be sent before the QAction::triggerred signal. right?

    Then I wouldn't do any fancy code. You just want to swap the order of these signals, then your code will work. There are several ways of doing this. Simplest, I think, would be to make the triggered menu action be connect()ed with a Qt::QueuedConnection. Then the slot won't be called till the event loop is hit, and presumably the dataChanged, connect()ed with Qt::DirectConnection, will have gone through first. That's what I would try, one line code change to see where you are.



  • Thank you @JonB .
    It was not a signal issue. It was the focusPolicy property of QMenuBar that the QtDesigner set by default to "NoFocus". Changing it to "ClickFocus" set the behavior correctly for my case.


Log in to reply