Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Windows Service with QT Gui and Tray Icon
this is my first Post here in this Forum, and i hope you can help me with some Tips. Sorry for my English.
Okey lets start.
I wrote a Windows Service, this Service is starting a other program and monitoring it like a "Watchdog". Now i wanna to create a tray icon, to show if the program is running. And with a click on the tray icon you can see some things about the process. Like the CPU percentage or special values.
Now i have the problem, to include the Qt - GUI to the windows service. Is there a trick or way to fix this. I don't need help with the other functions in the program, i just need to know how to implement Qt in a windows service. I don't use.net i just use the normal C++.
Thanks for your brainpower.
With best regards,
lgeyer last edited by
Windows Services are using a non-interactive window station, thus you cannot create a service that interacts with the user. You will have to create a seperate application that uses some kind of IPC to communicate with the service and fetch the required data.
AcerExtensa last edited by
The simplest way is to create second program, just for tray icon and communicate with your service through Events, Messages, Local Sockets, DDE or whatever you prefer...
Qt GUI needs main loop/QApplication instance... you can do it by creating QThread in your service and loop messages where(with native WINAPI it works).... but I'm guessing you will get troubles with Qt GUI in this meaner...
Oke thanks for your reply.
The problem is, i want to start the Windows Service at begin with a standard process. But i wanna give the user the ability to insert in the Gui an XML - File, which includes the path and some parameters. If the user include the file and press on start, the new process should be monitoring by the Windows Service. So i need to get the IPC like an interactive Windows Service program.
So if i do now a little brainstorming, i come at the end to this.
- Windows Service starts with normal monitoring.
- User insert new Xml - File
- Windows Service is looking every 300ms for an "Xml" - Event.
- If the Event is available, the WinService stop the current monitoring and take the new one.
- The trayicon - Gui is looking every 20ms for new values from the WinService and show it the user.
Do you confirm with this? Or is there a better way? Remember i don't need code, i just need the best way. The program should be very fast.
Very much thanks,
AcerExtensa last edited by
Wouldn't a Local Socket be a better choice?
- Start Service, bind tcp socket on some port and listen it
- GUI connects to tcp port of service(port can be stored somewhere in registry or just be a static port)
- User inserts new Xml - GUI send command over sockets to service(for example xml:datadatadata)
- Service parse command and execute needed functionality...
- GUI binds on another tcp socket, sends command to service(tcp:port) and listens on this port
- If where something to show to user in service, just send this to GUI over tcp
So you doesn't need loops to query each other...
You can also use named pipes or even RPC communication if you wish
Thanks for your reply, i was looking something for IPC that's better then my "loopshit" and i think Named Pipes would be the best for me.
Now i just need to create the IPC with the two processes.
Thanks for your help,