Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Windows Service with QT Gui and Tray Icon
Qt 6.11 is out! See what's new in the release blog

Windows Service with QT Gui and Tray Icon

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mr_einsa
    wrote on last edited by
    #1

    Hello,

    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,

    mr_einsa

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AcerExtensa
        wrote on last edited by
        #3

        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...

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mr_einsa
          wrote on last edited by
          #4

          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.

          1. Windows Service starts with normal monitoring.
          2. User insert new Xml - File
          3. Windows Service is looking every 300ms for an "Xml" - Event.
          4. If the Event is available, the WinService stop the current monitoring and take the new one.
          5. 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,

          mr_einsa

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #5

            Wouldn't a Local Socket be a better choice?

            1. Start Service, bind tcp socket on some port and listen it
            2. GUI connects to tcp port of service(port can be stored somewhere in registry or just be a static port)
            3. User inserts new Xml - GUI send command over sockets to service(for example xml:datadatadata)
            4. Service parse command and execute needed functionality...
            5. GUI binds on another tcp socket, sends command to service(tcp:port) and listens on this port
            6. 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

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mr_einsa
              wrote on last edited by
              #6

              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,

              mr_einsa

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved