QSystemTrayIcon keeps creating new icons

98 Views Asked by At

I've created a notification system that makes use of QSystemTrayIcon to alert the user. My issue is that each time a user receives a notification it creates a new icon so the system tray ends up full of these icons.

I develop the program on a Linux machine and the issue doesn't occur here. However, I build the program on Windows 7 which is where the program is actually used and where the issue arises. This makes testing tricky for me as I have to go through quite a lengthy process to even run the program on Windows. So I'm kind of hoping someone can spot the issue and tell me exactly what is wrong but I appreciate any input so please if you have any idea do tell.

My code:

QSystemTrayIcon* notiTray = new QSystemTrayIcon(this);
notiTray->setIcon(QIcon(":/icon.png"));
notiTray->setVisible(true);
notiTray->showMessage("Notifications, "You have new notifications", QSystemTrayIcon::Information, 60000);
notiTray->show();
QApplication::alert(this, 1000);

This code is inside an if statement inside a function that gets called every 5 seconds to check for new notifications.

At a guess I'd say it might be because a new SystemTrayIcon is made everytime a notification arises but I'm not 100% and I was hoping anyone might be able to confirm this to save me from going through an awful process of testing it on Windows.

Thanks for any help!

0

There are 0 best solutions below