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. Best practice: headless mode
QtWS25 Last Chance

Best practice: headless mode

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 9.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.
  • A Offline
    A Offline
    Aicou
    wrote on last edited by
    #1

    Hello,

    I have a software with a GUI and some Qnetwork and Qsettings features (kind of FTP client).

    I would like to add the possibility, when the soft is run with an option like "-auto", to run a 'default' upload with no GUI.

    My question is, is there a way to do it in Qt or do i have to create 2 different part of my soft (one using a QApplication, the other using a QCoreApplication) ?
    I look for this because I implement most of my function directly in my GUI objects :D (noob mistake i guest)

    Of course I look into the doc but I don't know if what I'm looking for even exist so I ask here too.

    thanks

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Start refactoring, I'd say, and separate your business logic from your UI.

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

        that's what i feared, thanks you Andre.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          Noboby forces you to show a UI, even when using a QApplication. The OS will still need to load all the UI libraries, which would not be necessary for a QCoreApplication. But that might be OK for your use case.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #5

            I agree with Tobias. It depends on if you want to simply not show a GUI, or if you really want to run your application in an environment that has no graphical capabilities. For the former, just don't show your widgets. For the latter, then as Andre says you will need to refactor a little. It is normally not too difficult to split out the functionality into a bunch of QObject derived classes.

            If you do want an app capable of running in a non-GUI environment in addition to the GUI version then I would suggest you look at pulling the functionality out into a shared library. You GUI and non-GUI apps then just become slim wrappers around the shared lib.

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Aicou
              wrote on last edited by
              #6

              yes, i'll try in the first time to run it just without displaying the GUI (it's for a windows environment so there will be a display anyway) but i was wondering how to start it after running the QApplication.exec()
              i could call a function before and make a little sleep on it to wait for the slot/signal to start but if you have a better idea it's welcome.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                It depends :-)

                I fyou have only synchronous things without waiting, you could just call it without the exec. otherwise make some QMetaObject::invoke(..., Queued...) stuff to start first thing and ensure to call some QApplication::quit in the end.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Aicou
                  wrote on last edited by
                  #8

                  yes i have some asynchronous stuf in Qftp but QMetaObject::invoke seams to be what i need, thanks ^^

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #9

                    welcome.

                    You should have some way to ensure, that when everything is done, the eventloop is closed. Otherwise the program runs forever.

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Aicou
                      wrote on last edited by
                      #10

                      everything work fine (recursive signal/slot is fun oO), thanks again

                      1 Reply Last reply
                      0
                      • Z Offline
                        Z Offline
                        ZapB
                        wrote on last edited by
                        #11

                        Good stuff. Glad you got it working. :)

                        Nokia Certified Qt Specialist
                        Interested in hearing about Qt related work

                        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