title: QT change QSystemTrayIcon at runtime
body: <p>I'm trying to change the <code>QSystemTrayIcon</code> at various points in my application, example:</p>
  
  <pre><code>void MainWindow::goOnline() {
  
      isOnlineFlag = true;
  
      QIcon xmediaIcon("://notificationLogo.png");
      sti-&gt;setIcon(xmediaIcon);
  }
  
  void MainWindow::goOffline(bool manual) {
  
      isOnlineFlag = false;
  
      QIcon xmediaIcon("://notificationLogoOffline.png");
      sti-&gt;setIcon(xmediaIcon);
  }
  </code></pre>
  
  <p>But for some reason the application crashes at times.</p>
  
  <p>Crash log:</p>
  
  <pre><code>Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
  0   QtGui                           0x0000000101813171 QIcon::operator=(QIcon const&amp;) + 33
  1   QtWidgets                       0x000000010207a2d6 QSystemTrayIcon::setIcon(QIcon const&amp;) + 22
  2   com.yourcompany.app             0x000000010002b089 MainWindow::goOffline(bool) + 617
  3   com.yourcompany.app             0x00000001000bb736 MainWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 19382
  4   QtCore                          0x00000001013edda6 QMetaObject::activate(QObject*, int, int, void**) + 2550
  5   QtCore                          0x00000001013e6c93 QObject::event(QEvent*) + 51
  6   QtWidgets                       0x0000000101d55f2c QApplicationPrivate::notify_helper(QObject*, QEvent*) + 300
  7   QtWidgets                       0x0000000101d58a1d QApplication::notify(QObject*, QEvent*) + 6157
  8   QtCore                          0x00000001013bd0b2 QCoreApplication::notifyInternal(QObject*, QEvent*) + 114
  9   QtCore                          0x000000010140e746 QTimerInfoList::activateTimers() + 982
  10  libqcocoa.dylib                 0x0000000104e58fc5 QCocoaEventDispatcherPrivate::activateTimersSourceCallback(void*) + 21
  11  com.apple.CoreFoundation        0x00007fff9038c731 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
  12  com.apple.CoreFoundation        0x00007fff9037dea2 __CFRunLoopDoSources0 + 242
  13  com.apple.CoreFoundation        0x00007fff9037d62f __CFRunLoopRun + 831
  14  com.apple.CoreFoundation        0x00007fff9037d0b5 CFRunLoopRunSpecific + 309
  15  com.apple.HIToolbox             0x00007fff86261a0d RunCurrentEventLoopInMode + 226
  16  com.apple.HIToolbox             0x00007fff862617b7 ReceiveNextEventCommon + 479
  17  com.apple.HIToolbox             0x00007fff862615bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
  18  com.apple.AppKit                0x00007fff837193de _DPSNextEvent + 1434
  19  com.apple.AppKit                0x00007fff83718a2b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
  20  com.apple.AppKit                0x00007fff8370cb2c -[NSApplication run] + 553
  21  libqcocoa.dylib                 0x0000000104e59d44 QCocoaEventDispatcher::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) + 2404
  22  QtCore                          0x00000001013ba64d QEventLoop::exec(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) + 397
  23  QtCore                          0x00000001013bd652 QCoreApplication::exec() + 354
  24  com.yourcompany.app             0x0000000100007906 main + 1558
  25  com.yourcompany.app             0x0000000100006584 start + 52
  </code></pre>
  
  <p>Any ideas what the problem could be?</p>