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. Qt service with gui
Forum Updated to NodeBB v4.3 + New Features

Qt service with gui

Scheduled Pinned Locked Moved Unsolved General and Desktop
25 Posts 7 Posters 3.0k Views 7 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.
  • franco.amatoF franco.amato

    I need my application to not be closed by a user who does not have administrative rights and I thought, therefore, of transforming it into a Windows service using the QtService located here: [https://skycoder42.github.io/QtService/index.html]
    I know that a Windows service usually doesn't have a GUI and I'm not sure it can have one. Unfortunately In my application I have to display the webcam content in a QtWidget and so I need a Gui. I'm wondering if the Windows service is the correct solution to solve my need and if it is, is it possible to show a gui?

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #4

    @franco-amato
    Cannot imagine what your use case is. But a Windows Service cannot normally have a UI. Rather than my guessing whether any of them work, you might Google for windows service with ui and have a look through the various questions/answers. I am not sure any of them will work, at least nowadays.

    franco.amatoF 1 Reply Last reply
    0
    • franco.amatoF franco.amato

      Can I have a help with the global design?

      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #5

      @franco-amato Usually design goes like this:
      you have one process running as a service, with privileges. The other one is with GUI and what not, doing actual work.
      While I am not sure how one can prevent gui process from being closed, the work of a service in this case would be to monitor/being notified about the closure and if that's the case, respawn the gui and possibly notify some API that the incident happened.

      For more information please re-read.

      Kind Regards,
      Artur

      JonBJ 1 Reply Last reply
      3
      • artwawA artwaw

        @franco-amato Usually design goes like this:
        you have one process running as a service, with privileges. The other one is with GUI and what not, doing actual work.
        While I am not sure how one can prevent gui process from being closed, the work of a service in this case would be to monitor/being notified about the closure and if that's the case, respawn the gui and possibly notify some API that the incident happened.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #6

        @artwaw said in Qt service with gui:

        respawn the gui

        I think that will be "tricky" from a service. For example, it doesn't have access to the desktop and it doesn't run as the desktop/logged on user.

        artwawA 1 Reply Last reply
        0
        • JonBJ JonB

          @franco-amato
          Cannot imagine what your use case is. But a Windows Service cannot normally have a UI. Rather than my guessing whether any of them work, you might Google for windows service with ui and have a look through the various questions/answers. I am not sure any of them will work, at least nowadays.

          franco.amatoF Offline
          franco.amatoF Offline
          franco.amato
          wrote on last edited by
          #7

          @JonB T Don't you think that I already performed a google search before posting here?

          JonBJ 1 Reply Last reply
          0
          • franco.amatoF franco.amato

            @JonB T Don't you think that I already performed a google search before posting here?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #8

            @franco-amato
            Not particularly, no. A lot of posters here don't, in fact probably most. And if they do they usually say so and what they came across. You asked if it is possible to show a GUI from a Windows service, and I suggested it is not, so far as I know.

            franco.amatoF 1 Reply Last reply
            0
            • JonBJ JonB

              @artwaw said in Qt service with gui:

              respawn the gui

              I think that will be "tricky" from a service. For example, it doesn't have access to the desktop and it doesn't run as the desktop/logged on user.

              artwawA Offline
              artwawA Offline
              artwaw
              wrote on last edited by
              #9

              @JonB said in Qt service with gui:

              it doesn't have access to the desktop and it doesn't run as the desktop/logged on user.

              Yeah BUT :) I assumed gui runs as an identifiable process, at least that's what I think OP implied here. You can monitor that from the service, right?

              The usual convenience (i.e. antivirus brought up previously) is that monitored gui runs for every user. And having a process running with privileges in the background I suppose you are able to discern which of your monitored processes runs under which user.

              To be honest I don't think it is a nice way of implementing any solution but that's the only way that comes to mind right now.

              For more information please re-read.

              Kind Regards,
              Artur

              JonBJ 1 Reply Last reply
              0
              • artwawA artwaw

                @JonB said in Qt service with gui:

                it doesn't have access to the desktop and it doesn't run as the desktop/logged on user.

                Yeah BUT :) I assumed gui runs as an identifiable process, at least that's what I think OP implied here. You can monitor that from the service, right?

                The usual convenience (i.e. antivirus brought up previously) is that monitored gui runs for every user. And having a process running with privileges in the background I suppose you are able to discern which of your monitored processes runs under which user.

                To be honest I don't think it is a nice way of implementing any solution but that's the only way that comes to mind right now.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #10

                @artwaw
                You can "monitor" a process from a service, but I don't see how that relates to what the OP is wanting.

                The example for anti-virus just seems to be: the non-UI part of the AV runs as a service (with privileges), the user chooses to fire up a user-process UI which happens to communicate with it. The UI process is fully user-level, nothing special about it, so far as I know. I don't think that is what the OP is asking for. But we shall see.

                artwawA 1 Reply Last reply
                0
                • JonBJ JonB

                  @artwaw
                  You can "monitor" a process from a service, but I don't see how that relates to what the OP is wanting.

                  The example for anti-virus just seems to be: the non-UI part of the AV runs as a service (with privileges), the user chooses to fire up a user-process UI which happens to communicate with it. The UI process is fully user-level, nothing special about it, so far as I know. I don't think that is what the OP is asking for. But we shall see.

                  artwawA Offline
                  artwawA Offline
                  artwaw
                  wrote on last edited by
                  #11

                  @JonB That's essentially what I wanted to say about the design, yes. And that would be my advice on how to implement functionality - using two processes: a monitor and a user-space gui. Unless Windows allows service to span a privileged process that a user can't interfere with but that's not a knowledge I possess.

                  For more information please re-read.

                  Kind Regards,
                  Artur

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @franco-amato
                    Not particularly, no. A lot of posters here don't, in fact probably most. And if they do they usually say so and what they came across. You asked if it is possible to show a GUI from a Windows service, and I suggested it is not, so far as I know.

                    franco.amatoF Offline
                    franco.amatoF Offline
                    franco.amato
                    wrote on last edited by
                    #12

                    @JonB no is not what I asked. You should re read my first post.

                    JonBJ 1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      Hi,

                      One possible cheat is that you use a QProcess to start a new instance of your application if somebody stops it.
                      From a design point of view, you can forbid your user to close the application by handling the close event yourself. A starting point might be the QSystemTrayIcon example.
                      Note that this does not protect your application from getting killed but you can still handle the usual interruption signals.
                      The system service + client application combo is still worth exploring as you can have the service providing the core functionality and the application being merely a front-end.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      franco.amatoF 1 Reply Last reply
                      2
                      • franco.amatoF franco.amato

                        @JonB no is not what I asked. You should re read my first post.

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by JonB
                        #14

                        @franco-amato said in Qt service with gui:

                        You should re read my first post.

                        I have read it many times, thanks. Best of luck showing a UI from a Windows service.

                        franco.amatoF 1 Reply Last reply
                        1
                        • JonBJ JonB

                          @franco-amato said in Qt service with gui:

                          You should re read my first post.

                          I have read it many times, thanks. Best of luck showing a UI from a Windows service.

                          franco.amatoF Offline
                          franco.amatoF Offline
                          franco.amato
                          wrote on last edited by
                          #15

                          @JonB said in Qt service with gui:

                          @franco-amato said in Qt service with gui:

                          You should re read my first post.

                          I have read it many times, thanks. Best of luck showing a UI from a Windows service.

                          If you had read it you would have seen that I stated the following: "I know that a Windows service usually doesn't have a GUI and I'm not sure it can have one". What I asked is whether the path of service is the right path or if there are other solutions to achieve my need

                          JonBJ 1 Reply Last reply
                          0
                          • franco.amatoF franco.amato

                            @JonB said in Qt service with gui:

                            @franco-amato said in Qt service with gui:

                            You should re read my first post.

                            I have read it many times, thanks. Best of luck showing a UI from a Windows service.

                            If you had read it you would have seen that I stated the following: "I know that a Windows service usually doesn't have a GUI and I'm not sure it can have one". What I asked is whether the path of service is the right path or if there are other solutions to achieve my need

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by JonB
                            #16

                            @franco-amato said in Qt service with gui:

                            If you had read it

                            Thanks again. It's always nice to try to help people, just what we like to hear.

                            I read your post carefully, as I said. All I ever answered was that I think you will find it difficult to run a UI from a service. You asked if that was the "right path", I suggested it is not. Sorry if you didn't want to hear that. Why don't you leave me out now, thanks.

                            1 Reply Last reply
                            1
                            • SGaistS SGaist

                              Hi,

                              One possible cheat is that you use a QProcess to start a new instance of your application if somebody stops it.
                              From a design point of view, you can forbid your user to close the application by handling the close event yourself. A starting point might be the QSystemTrayIcon example.
                              Note that this does not protect your application from getting killed but you can still handle the usual interruption signals.
                              The system service + client application combo is still worth exploring as you can have the service providing the core functionality and the application being merely a front-end.

                              franco.amatoF Offline
                              franco.amatoF Offline
                              franco.amato
                              wrote on last edited by
                              #17

                              @SGaist Can you help with a small example regarding this "One possible cheat is that you use a QProcess to start a new instance of your application if somebody stops it." ?

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #18
                                // rest of the code
                                int result = app.exec();
                                QProcess::startDetached("your_application");
                                return result;
                                

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                franco.amatoF 1 Reply Last reply
                                0
                                • SGaistS SGaist
                                  // rest of the code
                                  int result = app.exec();
                                  QProcess::startDetached("your_application");
                                  return result;
                                  
                                  franco.amatoF Offline
                                  franco.amatoF Offline
                                  franco.amato
                                  wrote on last edited by
                                  #19

                                  @SGaist said in Qt service with gui:

                                  // rest of the code
                                  int result = app.exec();
                                  QProcess::startDetached("your_application");
                                  return result;
                                  

                                  It worked but now I am not able to stop it anymore :)) and I am the admin

                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #20

                                    You will have to implement some checks to determine who stopped the application.

                                    Note that you also need to implement graceful shutdown for when you stop/restart your machine.

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    franco.amatoF 1 Reply Last reply
                                    1
                                    • SGaistS SGaist

                                      You will have to implement some checks to determine who stopped the application.

                                      Note that you also need to implement graceful shutdown for when you stop/restart your machine.

                                      franco.amatoF Offline
                                      franco.amatoF Offline
                                      franco.amato
                                      wrote on last edited by
                                      #21

                                      @SGaist said in Qt service with gui:

                                      You will have to implement some checks to determine who stopped the application.

                                      Note that you also need to implement graceful shutdown for when you stop/restart your machine.

                                      It's not clear what you mean with graceful shutdown. Can you give an example please?

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #22

                                        Simply when you want to shutdown or reboot the machine for example when applying security fixes, kernel update, system updates, etc.

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          Sikander Rafiq
                                          wrote on last edited by
                                          #23

                                          @franco.amato Will you be able to make QT service with GUI or launch QT app with GUI from Qt service?

                                          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