On 30/05/2021 17:47, Konstantin Shegunov wrote:
I was simply teasing. I was referring to this thread about QTBUG-71545[1], where I wanted the application to destroy its children explicitly so they see it as QCA, but I wasn't convincing enough. Whereas QWidget(s) are doing it in their destructors for their children for exactly the same reason, which was the "exception(s)" I was referring to.


Well, it's roughly in the same area...

But while the "rule" that a parent gets destroyed before the children do is well-established, and changing it is extremely invasive and error-prone (you'd force every single class to override their destructor and clean their children up), we don't quite have hard-established rules about:

1) if it's OK to create QObjects before creating a QCoreApplication¹
2) symmetrically, if it's OK for QObjects to outlive QCoreApplication
3) if it's OK for QObjects living in a QThread to outlive that thread's run() 4) if it's OK for QObjects living in a QThread to outlive the QThread object itself
5) if it's OK for a QObject living in a thread A to be destroyed in thread B
6) if it's OK to create a QObject/QCoreApplication in a non-main thread
7) if it's OK to destroy and recreate a QCoreApplication in the same process
7b) like 7, but recreate the QCoreApplication in a different thread


The answer to most of these is "it depends" / "yes, but..." / "no, unless...", and I don't like that kind of answer at all. They also imply the whether it's a good idea to use QObjects into Q_GLOBAL_STATIC.

¹ (... generalizing: if it's OK to touch ANY Qt API whatsoever outside a QCoreApplication lifetime; but let's stay on topic, and stick to QObjects.)



My finger-in-the-wind opinion would be:

1) no QObjects must be created before creating QCoreApplication (and the generalization: almost NO Qt APIs are OK to use before QCA)
2) no
3) QObjects living in a thread must be destroyed before the thread terminates (so, for QThread, before run() returns)
4) no
5) no (4+5= to me, QObjects aren't re-entrant)
6) yes, but for GUI apps, it may depend on the platform
7) ditto
7b) ditto

=> so I'd be against allowing QObjects into Q_GLOBAL_STATIC (violates 2 4 and 5, and possibly 1).


Thanks,
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to