I am running into a situation where I create a QSystemTrayIcon in the constructor of the main widget. But when I try to call show on it, it outputs about a dozen "Cannot move to target thread" messages. It still displays and is usable, but it is disconcerting to get any error messages. Here is the code:
Qt Code:
  1. IngestorGUI::IngestorGUI()
  2. {
  3. if(QSystemTrayIcon::isSystemTrayAvailable())
  4. {
  5. m_ptr_SystemTrayIcon = new QSystemTrayIcon();
  6. m_TrayIcon = QIcon("dmax_icon.png");
  7. m_ptr_SystemTrayIconContextMenu = new QMenu(this);
  8. m_ptr_actShowGui = new QAction(this);
  9. m_ptr_actShowGui->setText("Show Interface");
  10. m_ptr_actShowGui->setCheckable(true);
  11. connect(m_ptr_actShowGui,SIGNAL(changed()),this,SLOT(slotShowInterface()));
  12. m_ptr_SystemTrayIconContextMenu->addAction(m_ptr_actShowGui);
  13. m_ptr_SystemTrayIcon->setIcon(m_TrayIcon);
  14. m_ptr_SystemTrayIcon->setContextMenu(m_ptr_SystemTrayIconContextMenu);
  15. m_ptr_SystemTrayIcon->show();
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 

On a side note; Is there any way to force explorer to update the system tray when I shut down? It never seems to update until I mouse over it. I tried to hide the icon before deleting, but it still didn't update. here is my destructor code:
Qt Code:
  1. IngestorGUI::~IngestorGUI()
  2. {
  3. if(m_ptr_actShowGui != (QAction*) NULL)
  4. {
  5. delete m_ptr_actShowGui;
  6. }
  7. if(m_ptr_SystemTrayIconContextMenu != (QMenu*) NULL)
  8. {
  9. delete m_ptr_SystemTrayIconContextMenu;
  10. }
  11. if(m_ptr_SystemTrayIcon != (QSystemTrayIcon*)NULL)
  12. {
  13. m_ptr_SystemTrayIcon->hide();
  14. delete m_ptr_SystemTrayIcon;
  15. }
  16. }
To copy to clipboard, switch view to plain text mode