Deleting and recreating QApplication object
-
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? -
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.
-
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.
@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-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?
@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? -
@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?@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-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()
@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
-
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.
-
@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
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