Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt app fails to create the tray icon when it runs on startup

Tags:

qt

startup

tray

There actually is no problem with my code per se, but if I add my program to run on startup (i.e. every time the user logs in), it fails to create the tray icon, because, at the time it tries to, the taskbar is not yet created/initialized completely. Is there a solution for that? Right now I'm thinking about something like retrying 10 times with a 10 second interval.

like image 363
sashoalm Avatar asked Feb 25 '23 19:02

sashoalm


1 Answers

It certainly is a race condition. Retrying is a good idea, yes, but instead I'd do it with delays. Have the app launch but use a QTimer::singleShot() to delay for 5 seconds (or whatever) before trying to hookup with the taskbar. If you want to retry after that (which is probably a good idea), delay longer (as retrying immediately likely won't succeed either as the retry will occur too fast).

like image 166
Wes Hardaker Avatar answered Feb 27 '23 11:02

Wes Hardaker