Re: QSystemTrayIcon sometimes can’t show
-
Sorry that I'm creating new topic but I couldn't post new answer in my topic (click scrolled web page to the top). It is related to: http://qt-project.org/forums/viewthread/30322
Unfortunately problem still exists. I have this problem on my virtualbox KDE 32bit system. Seems that it occur when application starting slowly (I have limited RAM for this system so my application has slow start). On this system trayicon doesn't work on each start. My friend which have Xubuntu (XFCE) also confirmed that sometimes trayicon is show in left-top corner instead of tray bar. I'm also assigning context menu to tray icons. Is it possible that I'm doing something in wrong order?
This is my main proc (I'm creating tray icon here because this solved problem on my main physical system)@int main(int argc, char *argv[])
{
QApplication a(argc, argv);QtSingleApplication app(argc, argv); if (app.isRunning()) { QMessageBox::information(0, "Player", "Another instance is running"); return 0; } QSystemTrayIcon *t = new QSystemTrayIcon();
#if defined(Q_OS_LINUX)
t->setIcon(QIcon(":/images/22/player_play.png"));
#else
t->setIcon(QIcon(":/images/16/player_play.png"));
#endif
t->setVisible(true);MainWindow w; w.show(); w.mTray = t; w.createTray(); return a.exec(); delete t;
}@
And this is proc createTray in main window:
@void MainWindow::createTray()
{
mTrayMenu.addAction(ui->actionMainWindow);
mTrayMenu.addSeparator();
QList<QAction *> l;
l << ui->actionPlay << ui->actionStop << ui->actionNext << ui->actionPrevious;
mTrayMenu.addActions(l);
mTrayMenu.addSeparator();
mTrayMenu.addAction(ui->actionQuit);
connect(mTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
mTray->setContextMenu(&mTrayMenu);
}@