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. Deleting and recreating QApplication object
Qt 6.11 is out! See what's new in the release blog

Deleting and recreating QApplication object

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 223 Views 2 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.
  • A Offline
    A Offline
    abhic
    wrote last edited by
    #1

    My application has command line interface when user can run different commands. Some commands can launch a GUI and once that GUI exits control come backs to command line interface. GUI can be launched and then closed any number of times.

    Currently during each GUI launch I create a new QApplication object and I delete it once GUI exits.
    Is this approach of deleting and recreating QApplication object safe?

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote last edited by Kent-Dorfman
      #2

      It is probably the most safe way to do it. I believe QApplication initializes Qt context for the framework, so starting with a fresh object in each instance is probably the "safer" way to go, but maybe not the most efficient.

      For myself, I would avoid mixing command line and GUI in one app but would put them into different processes and use IPC to communicate between them when necessary.

      The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

      A 1 Reply Last reply
      1
      • Kent-DorfmanK Kent-Dorfman

        It is probably the most safe way to do it. I believe QApplication initializes Qt context for the framework, so starting with a fresh object in each instance is probably the "safer" way to go, but maybe not the most efficient.

        For myself, I would avoid mixing command line and GUI in one app but would put them into different processes and use IPC to communicate between them when necessary.

        A Offline
        A Offline
        abhic
        wrote last edited by
        #3

        @Kent-Dorfman
        Thanks for your response. I have read at some place that Qt is not made for such usage where QApplication object is recreated after deletion. It recommended to reuse same QApplication object within an application, though I couldnt find any such reference in documentation. This is why I wanted to check here in this forum.

        Also can you share why I should avoid mixing command line and GUI in one app?

        Kent-DorfmanK 1 Reply Last reply
        0
        • A abhic

          @Kent-Dorfman
          Thanks for your response. I have read at some place that Qt is not made for such usage where QApplication object is recreated after deletion. It recommended to reuse same QApplication object within an application, though I couldnt find any such reference in documentation. This is why I wanted to check here in this forum.

          Also can you share why I should avoid mixing command line and GUI in one app?

          Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote last edited by
          #4

          @abhic said in Deleting and recreating QApplication object:

          Also can you share why I should avoid mixing command line and GUI in one app?

          a) for the reason you mentioned above. If Qt is leaking between instances of QApplication (it shouldn't be), then process isolation guarantees no leaks.
          b) modularization - I can often smell an application that is the product of incremental development with little to no pre-coding design analysis. Your use-case has a scent of incremental development without sufficient pre-coding analysis.
          c) you have no guarantee that the GUI context can even be created from a command line application. Different OS environment may or may not let you spawn GUIs from command line...what if you ssh/telnet in remotely?

          The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

          jeremy_kJ 1 Reply Last reply
          0
          • Kent-DorfmanK Kent-Dorfman

            @abhic said in Deleting and recreating QApplication object:

            Also can you share why I should avoid mixing command line and GUI in one app?

            a) for the reason you mentioned above. If Qt is leaking between instances of QApplication (it shouldn't be), then process isolation guarantees no leaks.
            b) modularization - I can often smell an application that is the product of incremental development with little to no pre-coding design analysis. Your use-case has a scent of incremental development without sufficient pre-coding analysis.
            c) you have no guarantee that the GUI context can even be created from a command line application. Different OS environment may or may not let you spawn GUIs from command line...what if you ssh/telnet in remotely?

            jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote last edited by
            #5

            @Kent-Dorfman said in Deleting and recreating QApplication object:

            @abhic said in Deleting and recreating QApplication object:

            Also can you share why I should avoid mixing command line and GUI in one app?

            a) for the reason you mentioned above. If Qt is leaking between instances of QApplication (it shouldn't be), then process isolation guarantees no leaks.

            While a program can create and destroy the QCoreApplication instance multiple times*, cache objects, dynamically loaded libraries, etc may not be recreated from a clean initial state. QLibrary::unload() makes explicit mention of an inability to unload on macOS. Deleting and recreating might not accomplish what the OP is looking for.

            * - Some of the autotests rely on this ability. For example, tst_QCoreApplication::qAppName()

            Asking a question about code? http://eel.is/iso-c++/testcase/

            Kent-DorfmanK 1 Reply Last reply
            2
            • jeremy_kJ jeremy_k

              @Kent-Dorfman said in Deleting and recreating QApplication object:

              @abhic said in Deleting and recreating QApplication object:

              Also can you share why I should avoid mixing command line and GUI in one app?

              a) for the reason you mentioned above. If Qt is leaking between instances of QApplication (it shouldn't be), then process isolation guarantees no leaks.

              While a program can create and destroy the QCoreApplication instance multiple times*, cache objects, dynamically loaded libraries, etc may not be recreated from a clean initial state. QLibrary::unload() makes explicit mention of an inability to unload on macOS. Deleting and recreating might not accomplish what the OP is looking for.

              * - Some of the autotests rely on this ability. For example, tst_QCoreApplication::qAppName()

              Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote last edited by
              #6

              @jeremy_k said in Deleting and recreating QApplication object:

              While a program can create and destroy the QCoreApplication instance multiple times*, cache objects, dynamically loaded libraries, etc may not be recreated from a clean initial state. QLibrary::unload() makes explicit mention of an inability to unload on macOS. Deleting and recreating might not accomplish what the OP is looking for.

              OK. I'll concede that this may cause problems, but as that being the case then I'd suggest that it's a "fault" that the Qt frameworks folks should address. In my world, destroying QApplication should be a hard reset for the framework, and if it is not, then that makes me question the stability of the framework, but not enough to quit using it. LOL

              The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

              G 1 Reply Last reply
              0
              • A Offline
                A Offline
                abhic
                wrote last edited by
                #7

                Main command line interface application is pre existing older app and this GUI has been added much later. This relatively newly developed GUI interacts back and forth with the core application to send and receive data.

                Currently I am deleting and recreating QApplication object on GUI launch. I havn't faced any direct issue that points to this being a problem but there have been some other issues which might be completely unrelated to this or Qt code related to this GUI. But while exploring things I noticed this mentioned somewhere it is not a good idea to delete and recreate QApplication object so I just wanted to get the opinion here at the forum because I couldn't find anything explicitly mentioned in Qt documentation.

                1 Reply Last reply
                0
                • Kent-DorfmanK Kent-Dorfman

                  @jeremy_k said in Deleting and recreating QApplication object:

                  While a program can create and destroy the QCoreApplication instance multiple times*, cache objects, dynamically loaded libraries, etc may not be recreated from a clean initial state. QLibrary::unload() makes explicit mention of an inability to unload on macOS. Deleting and recreating might not accomplish what the OP is looking for.

                  OK. I'll concede that this may cause problems, but as that being the case then I'd suggest that it's a "fault" that the Qt frameworks folks should address. In my world, destroying QApplication should be a hard reset for the framework, and if it is not, then that makes me question the stability of the framework, but not enough to quit using it. LOL

                  G Offline
                  G Offline
                  GreatJobQTbeHostileToEvenNewbies
                  wrote last edited by
                  #8

                  @Kent-Dorfman

                  Moles and trolls...Moles and trolls...LOL

                  Seen your own DP lately? Great Projection, so very helpful to newbies this is surely helping Qt stay afloat. Oh whats this? https://news.ycombinator.com/item?id=28627022
                  “Engineers can't explain it, legal can't understand it", “What companies want is certainty… Qt lacks it”,"It’s not just cost — it’s fear of getting licensing wrong",,"Qt's corporate owners have been openly hostile to the community for a while" are common sayings in the community? I was even being well civil but now i shall and will be otherwise:

                  can't even answer lack of basic devops fundamental industry flows in QT, or improve itself while worse companies like microsoft can. May the likes of Oracle and Qt and others with majority investors from banking sectors may drown in their yachts in random storms.. metaphorically.

                  @Christian-Ehrlicher ban my soon to be autoscripted posts from my x many emails as x many times you want, truth will remain that Qt is abandonware without KDE and ugly frankenstein's monster with pinochio's nose thanks to yall bloodthirstynachtzikapitalists. You'r both getting traction at bilbili already. it will be fun :D Well i was able to rework my QT app to a better cross platform technology in just few hours and removed all Qt bs from my home now, also have I blocking my own account notifications coming from QT all ze bezt

                  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