QSystemTrayIcon thread issue
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:
Code:
IngestorGUI::IngestorGUI()
{
{
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,SLOT(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:
Code:
IngestorGUI::~IngestorGUI()
{
if(m_ptr_actShowGui
!= (QAction*) NULL) {
delete m_ptr_actShowGui;
}
if(m_ptr_SystemTrayIconContextMenu
!= (QMenu*) NULL) {
delete m_ptr_SystemTrayIconContextMenu;
}
{
m_ptr_SystemTrayIcon->hide();
delete m_ptr_SystemTrayIcon;
}
}
Re: QSystemTrayIcon thread issue
Are you using threads in your application?
Re: QSystemTrayIcon thread issue
I will be, but not yet. Right now this IngestorGUI object is created in main along with a QApplication. The QApplication is then executed. Here is the main code:
Code:
int main(int argc, char *argv[])
{
IngestorGUI window;
return app.exec();
}
Re: QSystemTrayIcon thread issue
Can you create a minimal example that only creates the tray icon and calls exec() on the application object and see if the problem persists? BTW. Which version of Qt are you using?
Re: QSystemTrayIcon thread issue
4.3.1
I will try that and post back.
EDIT: The issue persists on the minimal example.
Re: QSystemTrayIcon thread issue
This might be a bug in Qt. You might check if it was reported in the task-tracker.
Re: QSystemTrayIcon thread issue
Doesn't seem to be. Can anyone corroborate this issue on their system?
Re: QSystemTrayIcon thread issue
Could you post the minimal example? System Tray Icon Example gives me no warnings at all with Qt/Win 4.3.1.
Re: QSystemTrayIcon thread issue
Code:
#include <QApplication>
int main(int argc, char *argv[])
{
syst.
setIcon(QIcon("dmax_icon.png"));
syst.show();
return app.exec();
}
put the icon of your choice in place of the png