TheGrimace
25th September 2007, 19:56
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:
IngestorGUI::IngestorGUI()
{
if(QSystemTrayIcon::isSystemTrayAvailable())
{
m_ptr_SystemTrayIcon = new QSystemTrayIcon();
m_TrayIcon = QIcon("dmax_icon.png");
m_ptr_SystemTrayIconContextMenu = new QMenu(this);
m_ptr_actShowGui = new QAction(this);
m_ptr_actShowGui->setText("Show Interface");
m_ptr_actShowGui->setCheckable(true);
connect(m_ptr_actShowGui,SIGNAL(changed()),this,SL OT(slotShowInterface()));
m_ptr_SystemTrayIconContextMenu->addAction(m_ptr_actShowGui);
m_ptr_SystemTrayIcon->setIcon(m_TrayIcon);
m_ptr_SystemTrayIcon->setContextMenu(m_ptr_SystemTrayIconContextMenu);
m_ptr_SystemTrayIcon->show();
}
}
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:
IngestorGUI::~IngestorGUI()
{
if(m_ptr_actShowGui != (QAction*) NULL)
{
delete m_ptr_actShowGui;
}
if(m_ptr_SystemTrayIconContextMenu != (QMenu*) NULL)
{
delete m_ptr_SystemTrayIconContextMenu;
}
if(m_ptr_SystemTrayIcon != (QSystemTrayIcon*)NULL)
{
m_ptr_SystemTrayIcon->hide();
delete m_ptr_SystemTrayIcon;
}
}
IngestorGUI::IngestorGUI()
{
if(QSystemTrayIcon::isSystemTrayAvailable())
{
m_ptr_SystemTrayIcon = new QSystemTrayIcon();
m_TrayIcon = QIcon("dmax_icon.png");
m_ptr_SystemTrayIconContextMenu = new QMenu(this);
m_ptr_actShowGui = new QAction(this);
m_ptr_actShowGui->setText("Show Interface");
m_ptr_actShowGui->setCheckable(true);
connect(m_ptr_actShowGui,SIGNAL(changed()),this,SL OT(slotShowInterface()));
m_ptr_SystemTrayIconContextMenu->addAction(m_ptr_actShowGui);
m_ptr_SystemTrayIcon->setIcon(m_TrayIcon);
m_ptr_SystemTrayIcon->setContextMenu(m_ptr_SystemTrayIconContextMenu);
m_ptr_SystemTrayIcon->show();
}
}
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:
IngestorGUI::~IngestorGUI()
{
if(m_ptr_actShowGui != (QAction*) NULL)
{
delete m_ptr_actShowGui;
}
if(m_ptr_SystemTrayIconContextMenu != (QMenu*) NULL)
{
delete m_ptr_SystemTrayIconContextMenu;
}
if(m_ptr_SystemTrayIcon != (QSystemTrayIcon*)NULL)
{
m_ptr_SystemTrayIcon->hide();
delete m_ptr_SystemTrayIcon;
}
}