PDA

View Full Version : Systray icon no displayed under windows seven



flamaros
26th January 2011, 20:44
I make an application that run permanently that why I use a systray icon, but it's not displayed under windows seven. It's works fine on XP. I am using the .ico file that have a 32x32 resolution.

JohannesMunk
26th January 2011, 23:07
Hi!

I'm using the QSystemTrayIcon with a QIcon, that loads its data from a resource. Works like a charm in Win7 and XP.

Try to help yourself and build a minimal application, that just loads a systemtray icon.

Good luck,

Johannes

flamaros
12th February 2011, 14:10
I have made some tests. It works on only one PC that is really really strange, I have remove project and checkout it completely again to be sure there is no more files than on other PCs.
I also have made a minimal application that just works fine, but there is no difference with my project.

I am using visual studio 2010 with Qt Addins plugin 1.1.7 and Qt 4.7.1.
Not my qrc file is correctly loaded. I have put a break point in the generated file to check it.



int main(int argc, char* argv[])
{
TeSingleInstance instance("Service");

if (instance.isAnotherInstanceRunning())
return 0;

Q_INIT_RESOURCE(Service);

if (argc > 0)
{
QFileInfo info;

info.setFile(argv[0]);
QDir::setCurrent(info.canonicalPath());
}

QApplication application(argc, argv);
MainWindow window;

return application.exec();
}

MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
QCoreApplication::setOrganizationName("Tetraedge Games");
QCoreApplication::setOrganizationDomain("tetraedge.com");
QCoreApplication::setApplicationName("Service");
QApplication::setQuitOnLastWindowClosed(false);
QSettings::setDefaultFormat(QSettings::IniFormat);

mMainWindow.setupUi(this);

createActions();
createTrayIcon();
mSystemTray.icon->show();

// Do some connect to Ui events
}

void MainWindow::createActions()
{
mSystemTray.minimizeAction = new QAction(tr("Mi&nimize"), this);
connect(mSystemTray.minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));

mSystemTray.maximizeAction = new QAction(tr("Ma&ximize"), this);
connect(mSystemTray.maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));

mSystemTray.restoreAction = new QAction(tr("&Restore"), this);
connect(mSystemTray.restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));

mSystemTray.settingsAction = new QAction(tr("&Settings"), this);
connect(mSystemTray.settingsAction, SIGNAL(triggered()), this, SLOT(onSettingsActionTriggered()));

mSystemTray.quitAction = new QAction(tr("&Quit"), this);
connect(mSystemTray.quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}

void MainWindow::createTrayIcon()
{
mSystemTray.menu = new QMenu(this);
mSystemTray.menu->addAction(mSystemTray.minimizeAction);
mSystemTray.menu->addAction(mSystemTray.maximizeAction);
mSystemTray.menu->addAction(mSystemTray.restoreAction);
mSystemTray.menu->addSeparator();
mSystemTray.menu->addAction(mSystemTray.settingsAction);
mSystemTray.menu->addSeparator();
mSystemTray.menu->addAction(mSystemTray.quitAction);

mIcon.addFile(":/myIcon.ico");
mSystemTray.icon = new QSystemTrayIcon(this);
mSystemTray.icon->show();
mSystemTray.icon->setIcon(mIcon);
setWindowIcon(mIcon);
mSystemTray.icon->setContextMenu(mSystemTray.menu);
}