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. How to create a Windows Service using C++/QT?

How to create a Windows Service using C++/QT?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 4.0k Views
  • 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.
  • A Offline
    A Offline
    amitgolhani
    wrote on last edited by amitgolhani
    #1

    Hi,

    I have a GUI application which is based on QT/C++. It can be any simple QT/C++ application. I want to run this application as a window service. Actually my requirement is that whenever the machine turns to restart, then my GUI application should run automatically. There should not wait for system login to run it. It should ready and doing its job before the system login. Whenever we login the system it must appear on the screen (or) appear in the system trey. If it appears in the system tray, then double clicked on it, then it must appear on the screen.

    Kindly suggest me what should I do to achieve the same. If possible please share me the sample code for the same.

    Thanks...

    jsulmJ 1 Reply Last reply
    0
    • A amitgolhani

      Hi,

      I have a GUI application which is based on QT/C++. It can be any simple QT/C++ application. I want to run this application as a window service. Actually my requirement is that whenever the machine turns to restart, then my GUI application should run automatically. There should not wait for system login to run it. It should ready and doing its job before the system login. Whenever we login the system it must appear on the screen (or) appear in the system trey. If it appears in the system tray, then double clicked on it, then it must appear on the screen.

      Kindly suggest me what should I do to achieve the same. If possible please share me the sample code for the same.

      Thanks...

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @amitgolhani What you describe doesn't sound like a service. It is simply autostart of your app. There is nothing special about it.
      On Windows 10 you can simply create a link to your executable in USE_NAME/AppData/Roaming/Microsoft/Windows/Start/Programs/Autostart. Installer can do this.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      0
      • jsulmJ jsulm

        @amitgolhani What you describe doesn't sound like a service. It is simply autostart of your app. There is nothing special about it.
        On Windows 10 you can simply create a link to your executable in USE_NAME/AppData/Roaming/Microsoft/Windows/Start/Programs/Autostart. Installer can do this.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @jsulm , @amitgolhani

        I have a GUI application which is based on QT/C++.
        ...
        Actually my requirement is that whenever the machine turns to restart, then my GUI application should run automatically. There should not wait for system login to run it.

        Can you run a Windows "GUI" application from machine start, with no login, and therefore no desktop? I would doubt it...

        jsulmJ 1 Reply Last reply
        0
        • JonBJ JonB

          @jsulm , @amitgolhani

          I have a GUI application which is based on QT/C++.
          ...
          Actually my requirement is that whenever the machine turns to restart, then my GUI application should run automatically. There should not wait for system login to run it.

          Can you run a Windows "GUI" application from machine start, with no login, and therefore no desktop? I would doubt it...

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @JonB You're right I was confused by "Whenever we login the system it must appear on the screen". Yes, a service does not have an UI.
          @amitgolhani I think you will need to split your app into two parts:

          1. Background service without any UI
          2. UI front-end

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          JonBJ 1 Reply Last reply
          0
          • jsulmJ jsulm

            @JonB You're right I was confused by "Whenever we login the system it must appear on the screen". Yes, a service does not have an UI.
            @amitgolhani I think you will need to split your app into two parts:

            1. Background service without any UI
            2. UI front-end
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @jsulm
            I don't know, I just threw it in there. I don't think your original, simpler suggestion is "wrong", rather I think the OP needs to clarify just what he wants with this in mind. It would be a lot easier if he could skip the "before login" and just do what you suggested.

            Yes, a service does not have an UI.

            If he does need to use a Windows Service, when a Service is configured, Properties > Log On. Assuming this service can be run under default Local System account, there is an Allow service to interact with desktop checkbox. I use this in a (non-Qt) application which is principally a Service (does scheduling jobs), but also allows the user to invoke it (manually) with a command-line option requesting a UI for configuring the job schedules. OP should investigate whether that does allow the kind of (delayed) interaction he has in mind? It may do, I can't recall.

            My "fear" would then be: Suppose the way it works is that a Service can do UI stuff, but it will block on the first UI call till there is a login/desktop. Now if his application goes something like QtWidgets.QApplication(sys.argv) "early", I don't know if that Qt call would try to start from a UI and therefore block at that point? Stuff for him to investigate :)

            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