I think you should create the QIcon on the heap with new.
In your code the QIcon icon goes out of scope when the foo::createTrayIcon() functions ends...

i'm not sure....
sorry