Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[solved] Multiple trayicons appear, per process
My app has no window, the only Qt ui is the tray icon.
The app opens a chromium browser (CEF) and that causes a few new process to run.
What happens is that for each chromium process another icon appears in the tray, exactly like the initial one (including the icon and menu).
There's nothing in my code to suggest that something like that should happen, I start the chromium from a different thread and there's nothing to do with Qt in that part of the code.
Here's how I create the tray icon:
this->trayIcon = new QSystemTrayIcon(QIcon(TRAYICON_IMAGE), qApp); this->trayIcon->setContextMenu(this->trayIconMenu); this->trayIcon->setToolTip(TRAYICON_TOOLTIP);
Any ideas as for why that should happen and/or how to solve it so that there will be only that one initial tray icon?
On what platform do you have that happening ? I recall a long time ago I had something like that on Windows but hovering the mouse cursor over the icons made them disappear
I'm also on windows (8.1) and hovering doesn't make them disappear, sometimes a process will start and then stop and in that case the icon for that process will indeed disappear when hovered, but while the process is up and running the icon is there to stay.
Also, I think that even if they would go away when hovered, it's still far from being ideal..
How are you starting chromium ?
I start a new boost thread and in it I run CEF:
CefInitialize(main_args, settings, app.get(), sandbox_info); CefRunMessageLoop(); CefShutdown();
That creates a few new processes which all have an icon in the tray
Can you provide a minimal example that reproduces this ?
I can write a short Qt program that uses CEF and result in the problem I asked about, but it requires the CEF to downloaded and built on your system which sounds kinda like too much to ask for.
In the process manager I can see that for each new process that is created for chrome the name is the same as my app (i.e.: MyQtApp.exe), which maybe causes the system to use the same icon as I've set up for the main one?
So it looks like the part where you setup the QSystemTrayIcon is called each time you start that process ?
No, I thought so as well at first but I've set a break point to check if that's the case and it is not.
I think that what happens is that the system associates that icon with my process name (or something similar) and then just adds an icon per process of the same name.
Can something like that happen?
Know what, now that I think about it the debugger won't hit that break point since it's another process which it isn't debugging. Even my logs are probably overriding each other...
That's probably the problem, I'll start the chromium in another way.
Do the copy react on mouse click ?
I don't understand the question.. what mouse click?
I mean that if you have a menu or something on your QSystemTrayIcon, do the duplicate also show it ?
Yes, everything was "cloned".
But the problem was indeed that my process would just start over and over again.
What happens is that chromium starts up more process, all of them are the same executable as the one who started it to begin with.
In your code you need to check whether it is a chromium process (by the command line arguments) and if so call a chromium command to handle this process.
I missed that point and so it would just start my (Qt) app over and over again.
I did not get what's going on because the logs would just get overridden and no break points got hit because the debugger was attached to the original process...
Sorry for wasting time on this, it's just such a weird scenario which I faced for the first time..