PDA

View Full Version : How to receive notifications when a QList has been changed?



grayfox
22nd April 2012, 14:58
Consider this code:


QMenuBar bar;
bar.actions().append(new QAction("Hello World"));


QMenuBar returns a QList of QAction pointer, after I appended a new action, how does QMenuBar be notified on the change, so that it can update the UI accordingly?

I also tried to create a class that inherits from QList and I found no way to be notified when the list is changed.

Thanks in advance.

norobro
22nd April 2012, 23:20
You're going about it backwards. You add an action to QMenuBar or QMenu and then get a new QList of QActions.

From the docs (http://qt-project.org/doc/qt-4.8/qmenu.html#actions):
A menu consists of a list of action items. Actions are added with the addAction(), addActions() and insertAction() functions. An action is represented vertically and rendered by QStyle. In addition, actions can have a text label, an optional icon drawn on the very left side, and shortcut key sequence such as "Ctrl+X".

The existing actions held by a menu can be found with actions().