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 Application like daemon. How?

Qt Application like daemon. How?

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 1.6k 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.
  • B Offline
    B Offline
    bogong
    wrote on 16 Aug 2023, 08:19 last edited by bogong
    #1

    Hello!

    Is there any example of how to develop daemon application with Qt 6? Can't find anything. Is it the same like with Qt 5.

    Need to develop application that will be working on Windows, Linux and MacOS like daemon. Is there in-box solution for it in Qt? The functionality for this application looks like:

    • passing some commands from console while it's working and handling them in application
    • running it like daemon on all desktop (Windows, Linux and MacOS) or server
    K 1 Reply Last reply 16 Aug 2023, 08:29
    0
    • K Offline
      K Offline
      kkoehne
      Moderators
      wrote on 16 Aug 2023, 08:26 last edited by
      #2

      I don't think there's an abstraction for cross-platform 'daemons' or services. Anyhow, I understand the difference between a normal (console) program and a daemon is mostly in the setup / installation; so I don't see any issues with using Qt in such executables.

      Director R&D, The Qt Company

      1 Reply Last reply
      0
      • B bogong
        16 Aug 2023, 08:19

        Hello!

        Is there any example of how to develop daemon application with Qt 6? Can't find anything. Is it the same like with Qt 5.

        Need to develop application that will be working on Windows, Linux and MacOS like daemon. Is there in-box solution for it in Qt? The functionality for this application looks like:

        • passing some commands from console while it's working and handling them in application
        • running it like daemon on all desktop (Windows, Linux and MacOS) or server
        K Offline
        K Offline
        kkoehne
        Moderators
        wrote on 16 Aug 2023, 08:29 last edited by
        #3

        @bogong said in Qt Application like daemon. How?:

        passing some commands from console while it's working and handling them in application

        Daemons as executables can get command line arguments upon start. Anyhow, if you want to establish some communication to a running daemon, you can't IMO work with terminal I/O, as daemons typically do not have a terminal.

        Instead, you typically would use local sockets (e.g. QLocalSocket).

        Director R&D, The Qt Company

        B 1 Reply Last reply 16 Aug 2023, 08:42
        2
        • K kkoehne
          16 Aug 2023, 08:29

          @bogong said in Qt Application like daemon. How?:

          passing some commands from console while it's working and handling them in application

          Daemons as executables can get command line arguments upon start. Anyhow, if you want to establish some communication to a running daemon, you can't IMO work with terminal I/O, as daemons typically do not have a terminal.

          Instead, you typically would use local sockets (e.g. QLocalSocket).

          B Offline
          B Offline
          bogong
          wrote on 16 Aug 2023, 08:42 last edited by bogong
          #4

          @kkoehne What is the best practice if there need to develop kind of server application that will be working on any platform? Maybe there are mistakenly used term "daemon". There were for me 99 percents of mobile application with Qt. For now need to create application that will be working like server. Will be in memory keeping running listener of the port. Is there any examples?

          For example:

          • command to start application
          ./application start
          
          • command to stop application
          ./application stop
          
          • command to change state of application
          ./application state 1
          
          • command to handle anything
          ./application do_anything
          

          While application running need to have an ability to pass arguments and if application already running to handle arguments.

          J K 2 Replies Last reply 16 Aug 2023, 09:00
          0
          • B bogong
            16 Aug 2023, 08:42

            @kkoehne What is the best practice if there need to develop kind of server application that will be working on any platform? Maybe there are mistakenly used term "daemon". There were for me 99 percents of mobile application with Qt. For now need to create application that will be working like server. Will be in memory keeping running listener of the port. Is there any examples?

            For example:

            • command to start application
            ./application start
            
            • command to stop application
            ./application stop
            
            • command to change state of application
            ./application state 1
            
            • command to handle anything
            ./application do_anything
            

            While application running need to have an ability to pass arguments and if application already running to handle arguments.

            J Offline
            J Offline
            JonB
            wrote on 16 Aug 2023, 09:00 last edited by
            #5

            @bogong said in Qt Application like daemon. How?:

            What is the best practice if there need to develop kind of server application that will be working on any platform?

            I don't think there is anything much for a server/daemon across different platforms, as they all work differently. For example, although I don't develop for mobile/Android, I believe you have to do something Android-specific to make an application run as a daemon in the background.

            As @kkoehne said, you usually cannot do anything like re-run an application with a new command line argument as that would invoke a new instance of the application. You usually communicate with a running program via a socket message or something similar.

            1 Reply Last reply
            2
            • B bogong
              16 Aug 2023, 08:42

              @kkoehne What is the best practice if there need to develop kind of server application that will be working on any platform? Maybe there are mistakenly used term "daemon". There were for me 99 percents of mobile application with Qt. For now need to create application that will be working like server. Will be in memory keeping running listener of the port. Is there any examples?

              For example:

              • command to start application
              ./application start
              
              • command to stop application
              ./application stop
              
              • command to change state of application
              ./application state 1
              
              • command to handle anything
              ./application do_anything
              

              While application running need to have an ability to pass arguments and if application already running to handle arguments.

              K Offline
              K Offline
              kkoehne
              Moderators
              wrote on 16 Aug 2023, 09:01 last edited by kkoehne
              #6

              @bogong , you want to split things up in two executables: One 'control' application (in your case called application that is the interface to the user, and the actual server (let's call it server). Both can be command line applications; that is , they don't typically link against Qt GUI, and use QCoreApplication in their main.cpp.

              I'm not aware of any example that does exactly what you want (though it might be a nice addition in the future). But there's examples how client and serve communicate, take e.g. https://doc.qt.io/qt-6/qtdbus-pingpong-example.html .

              @bogong said in Qt Application like daemon. How?:

              For example:

              command to start application
              [...]

              Well, such custom commands for managing a service's state is not the 'usual' paradigm for services. On Windows, people are used to start and stop services from the GUI, or via sc. On Linux, you'd typically rather use something like systemctrl to start and stop services.

              Think about the following scenarios:

              • Should the server continue to run when the console / terminal you launched applicationfrom is closed?
              • Can there be multiple servers running at the same time?
              • Should the server be started again after the OS reboots?

              If you check all these boxes, you most certainly implement a 'real' server (so a Windows Service, for instance). If you check only the first or maybe the second option, you might get away with a normal executable that 'just' is detaches from the parent process.

              Director R&D, The Qt Company

              J B 3 Replies Last reply 16 Aug 2023, 09:13
              0
              • K kkoehne
                16 Aug 2023, 09:01

                @bogong , you want to split things up in two executables: One 'control' application (in your case called application that is the interface to the user, and the actual server (let's call it server). Both can be command line applications; that is , they don't typically link against Qt GUI, and use QCoreApplication in their main.cpp.

                I'm not aware of any example that does exactly what you want (though it might be a nice addition in the future). But there's examples how client and serve communicate, take e.g. https://doc.qt.io/qt-6/qtdbus-pingpong-example.html .

                @bogong said in Qt Application like daemon. How?:

                For example:

                command to start application
                [...]

                Well, such custom commands for managing a service's state is not the 'usual' paradigm for services. On Windows, people are used to start and stop services from the GUI, or via sc. On Linux, you'd typically rather use something like systemctrl to start and stop services.

                Think about the following scenarios:

                • Should the server continue to run when the console / terminal you launched applicationfrom is closed?
                • Can there be multiple servers running at the same time?
                • Should the server be started again after the OS reboots?

                If you check all these boxes, you most certainly implement a 'real' server (so a Windows Service, for instance). If you check only the first or maybe the second option, you might get away with a normal executable that 'just' is detaches from the parent process.

                J Offline
                J Offline
                JonB
                wrote on 16 Aug 2023, 09:13 last edited by
                #7

                @kkoehne said in Qt Application like daemon. How?:

                On Windows, people are used to start and stop services [from the GUI,] or via sc.

                And just so @bogong knows, this works only because Windows services/sc sends a message to your already-running daemon for further commands like "stop" or "pause". And you have to write your application as a service to support this. And of course it's quite Windows-specific.

                1 Reply Last reply
                0
                • K kkoehne
                  16 Aug 2023, 09:01

                  @bogong , you want to split things up in two executables: One 'control' application (in your case called application that is the interface to the user, and the actual server (let's call it server). Both can be command line applications; that is , they don't typically link against Qt GUI, and use QCoreApplication in their main.cpp.

                  I'm not aware of any example that does exactly what you want (though it might be a nice addition in the future). But there's examples how client and serve communicate, take e.g. https://doc.qt.io/qt-6/qtdbus-pingpong-example.html .

                  @bogong said in Qt Application like daemon. How?:

                  For example:

                  command to start application
                  [...]

                  Well, such custom commands for managing a service's state is not the 'usual' paradigm for services. On Windows, people are used to start and stop services from the GUI, or via sc. On Linux, you'd typically rather use something like systemctrl to start and stop services.

                  Think about the following scenarios:

                  • Should the server continue to run when the console / terminal you launched applicationfrom is closed?
                  • Can there be multiple servers running at the same time?
                  • Should the server be started again after the OS reboots?

                  If you check all these boxes, you most certainly implement a 'real' server (so a Windows Service, for instance). If you check only the first or maybe the second option, you might get away with a normal executable that 'just' is detaches from the parent process.

                  B Offline
                  B Offline
                  bogong
                  wrote on 16 Aug 2023, 09:23 last edited by
                  #8

                  @kkoehne said in Qt Application like daemon. How?:

                  Should the server continue to run when the console / terminal you launched applicationfrom is closed?

                  Yes it should be running after terminal closed

                  @kkoehne said in Qt Application like daemon. How?:

                  Can there be multiple servers running at the same time?

                  From begin there are no this kind of requirements. Just one instance of application on one physical or virtual server

                  @kkoehne said in Qt Application like daemon. How?:

                  Should the server be started again after the OS reboots?

                  Yes it should be starting after server reboot within the last state of the server.

                  J 1 Reply Last reply 16 Aug 2023, 09:26
                  0
                  • K kkoehne
                    16 Aug 2023, 09:01

                    @bogong , you want to split things up in two executables: One 'control' application (in your case called application that is the interface to the user, and the actual server (let's call it server). Both can be command line applications; that is , they don't typically link against Qt GUI, and use QCoreApplication in their main.cpp.

                    I'm not aware of any example that does exactly what you want (though it might be a nice addition in the future). But there's examples how client and serve communicate, take e.g. https://doc.qt.io/qt-6/qtdbus-pingpong-example.html .

                    @bogong said in Qt Application like daemon. How?:

                    For example:

                    command to start application
                    [...]

                    Well, such custom commands for managing a service's state is not the 'usual' paradigm for services. On Windows, people are used to start and stop services from the GUI, or via sc. On Linux, you'd typically rather use something like systemctrl to start and stop services.

                    Think about the following scenarios:

                    • Should the server continue to run when the console / terminal you launched applicationfrom is closed?
                    • Can there be multiple servers running at the same time?
                    • Should the server be started again after the OS reboots?

                    If you check all these boxes, you most certainly implement a 'real' server (so a Windows Service, for instance). If you check only the first or maybe the second option, you might get away with a normal executable that 'just' is detaches from the parent process.

                    B Offline
                    B Offline
                    bogong
                    wrote on 16 Aug 2023, 09:26 last edited by
                    #9

                    @kkoehne said in Qt Application like daemon. How?:

                    I'm not aware of any example that does exactly what you want (though it might be a nice addition in the future). But there's examples how client and serve communicate, take e.g. https://doc.qt.io/qt-6/qtdbus-pingpong-example.html .

                    This is what been seeking. Technically it looks like 2 different applications communicating between each other. And one in role of User Interface and the second in role of Server. Is there any way to prohibit running application within Server role from direct running? Is there way to run server only from User Interface application?

                    1 Reply Last reply
                    0
                    • B bogong
                      16 Aug 2023, 09:23

                      @kkoehne said in Qt Application like daemon. How?:

                      Should the server continue to run when the console / terminal you launched applicationfrom is closed?

                      Yes it should be running after terminal closed

                      @kkoehne said in Qt Application like daemon. How?:

                      Can there be multiple servers running at the same time?

                      From begin there are no this kind of requirements. Just one instance of application on one physical or virtual server

                      @kkoehne said in Qt Application like daemon. How?:

                      Should the server be started again after the OS reboots?

                      Yes it should be starting after server reboot within the last state of the server.

                      J Offline
                      J Offline
                      JonB
                      wrote on 16 Aug 2023, 09:26 last edited by
                      #10

                      @bogong
                      As far as I know you will need to take different platform-specific actions for this for each of your target OSes.

                      Yes it should be starting after server reboot within the last state of the server.

                      For sure that requires at least special installation for each OS. And as for "restoring whatever the last state" means to you, you will have to code for this, e.g. by saving state to a file.

                      B 1 Reply Last reply 16 Aug 2023, 09:28
                      0
                      • J JonB
                        16 Aug 2023, 09:26

                        @bogong
                        As far as I know you will need to take different platform-specific actions for this for each of your target OSes.

                        Yes it should be starting after server reboot within the last state of the server.

                        For sure that requires at least special installation for each OS. And as for "restoring whatever the last state" means to you, you will have to code for this, e.g. by saving state to a file.

                        B Offline
                        B Offline
                        bogong
                        wrote on 16 Aug 2023, 09:28 last edited by
                        #11

                        @JonB said in Qt Application like daemon. How?:

                        And as for "restoring whatever the last state" means to you, you will have to code for this, e.g. by saving state to a file.

                        Thx for reply. How to save the states - well known for me. But don't know how to run Qt application properly in background.

                        K 1 Reply Last reply 16 Aug 2023, 09:31
                        0
                        • B bogong
                          16 Aug 2023, 09:28

                          @JonB said in Qt Application like daemon. How?:

                          And as for "restoring whatever the last state" means to you, you will have to code for this, e.g. by saving state to a file.

                          Thx for reply. How to save the states - well known for me. But don't know how to run Qt application properly in background.

                          K Offline
                          K Offline
                          kkoehne
                          Moderators
                          wrote on 16 Aug 2023, 09:31 last edited by
                          #12

                          @bogong

                          Btw, just found https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice :) Looks like it at least compiles with Qt 5.15, so it might be a good template.

                          Director R&D, The Qt Company

                          B 1 Reply Last reply 16 Aug 2023, 09:33
                          2
                          • K kkoehne
                            16 Aug 2023, 09:31

                            @bogong

                            Btw, just found https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice :) Looks like it at least compiles with Qt 5.15, so it might be a good template.

                            B Offline
                            B Offline
                            bogong
                            wrote on 16 Aug 2023, 09:33 last edited by bogong
                            #13

                            @kkoehne said in Qt Application like daemon. How?:

                            Btw, just found https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice :) Looks like it at least compiles with Qt 5.15, so it might be a good template.

                            Wow! It looks like of what been seeking. Will test it out with Qt 6 and unite with D-Bus example if needed. Will reply here with results of experiments.

                            J JoeCFDJ 2 Replies Last reply 16 Aug 2023, 10:19
                            0
                            • B bogong
                              16 Aug 2023, 09:33

                              @kkoehne said in Qt Application like daemon. How?:

                              Btw, just found https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice :) Looks like it at least compiles with Qt 5.15, so it might be a good template.

                              Wow! It looks like of what been seeking. Will test it out with Qt 6 and unite with D-Bus example if needed. Will reply here with results of experiments.

                              J Offline
                              J Offline
                              JonB
                              wrote on 16 Aug 2023, 10:19 last edited by
                              #14

                              @bogong
                              For the record, it looks like that was for Qt4 and not updated since then? Not that it's not useful, just that it may need some updating.

                              1 Reply Last reply
                              0
                              • B bogong
                                16 Aug 2023, 09:33

                                @kkoehne said in Qt Application like daemon. How?:

                                Btw, just found https://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtservice :) Looks like it at least compiles with Qt 5.15, so it might be a good template.

                                Wow! It looks like of what been seeking. Will test it out with Qt 6 and unite with D-Bus example if needed. Will reply here with results of experiments.

                                JoeCFDJ Offline
                                JoeCFDJ Offline
                                JoeCFD
                                wrote on 16 Aug 2023, 18:16 last edited by
                                #15

                                @bogong I guess service is what you need on Linux/MacOS. Qt may not be needed here at all.

                                1 Reply Last reply
                                0
                                • J JonB referenced this topic on 17 Mar 2025, 17:12

                                3/15

                                16 Aug 2023, 08:29

                                12 unread
                                • Login

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