title: How can I dynamically add actions to a QMenu while it is open on a Mac?
body: <p>I have <code>QSystemTrayIcon</code> with a <code>QMenu</code>. In order to fill the menu, I need to fetch some things from the network, so I want to do that in the background.</p>
  
  <p>So I have a <code>QThread</code> with a slot that is connected to the <code>activated</code> signal of the tray icon. Then the thread fetches the resources and updates the menu using another signal.</p>
  
  <p>However, these updates do not show until I close and reopen the menu.</p>
  
  <p>This seems to be a Mac specific problem. I ran my code on Windows, and there it updated more or less correctly. Is there any workaround?</p>
  
  <p>Below is an extracted version of the problem. When the menu is opened, it will sleep 1 second in a thread and then change the menu. This change is not seen.</p>
  
  <pre><code>import sys
  import time
  from PySide import QtCore, QtGui
  
  class PeerMenu(QtGui.QMenu):
  
      def __init__(self):
          QtGui.QMenu.__init__(self)
          self.set_peers("prestine")
  
      @QtCore.Slot(object)
      def set_peers(self, label):
          self.clear()
  
          self.addAction(QtGui.QAction(label, self))
          self.addSeparator()
          self.addAction(QtGui.QAction("Hello", self))
  
  class GUIListener(QtCore.QObject):
  
      files = QtCore.Signal(object)
  
      def __init__(self):
          QtCore.QObject.__init__(self)
          self.counter = 0
  
      @QtCore.Slot()
      def check(self):
          time.sleep(1)
          self.counter += 1
          self.files.emit(str(self.counter))
  
  if __name__ == '__main__':
  
      app = QtGui.QApplication(sys.argv)
  
      icon = QtGui.QSystemTrayIcon(QtGui.QIcon('images/glyphicons-206-electricity.png'), app)
  
      listener = GUIListener()
      t = QtCore.QThread()
      t.start()
      listener.moveToThread(t)
  
      menu = PeerMenu()
      icon.activated.connect(listener.check)
      listener.files.connect(menu.set_peers)
  
      icon.setContextMenu(menu)
  
      icon.show()
  
      app.exec_()
  </code></pre>