Hi, > Second, it's also easy to forget that since there's no receiver/context, > the connection is always forced to be *direct*, which complicates things > if multiple threads are involved.
I'm not a module maintainer, but I remember fixing a bug in Qt Bluetooth which was caused by exactly this issue. And I must admit that it was rather difficult to detect it. So, I think that this macro is useful. Best regards, ------------------------------ Ivan Solovev Senior Software Engineer The Qt Company GmbH Erich-Thilo-Str. 10 12489 Berlin, Germany ivan.solo...@qt.io www.qt.io Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B ________________________________ From: Development <development-boun...@qt-project.org> on behalf of Giuseppe D'Angelo via Development <development@qt-project.org> Sent: Monday, July 10, 2023 6:02 PM To: development@qt-project.org <development@qt-project.org> Subject: [Development] Module maintainers: QT_NO_CONTEXTLESS_CONNECT in your modules Hi, https://codereview.qt-project.org/c/qt/qtbase/+/487560 introduces QT_NO_CONTEXTLESS_CONNECT , a macro that disables the 3-arguments connect -- in other words, it disables the > QObject::connect(sender, signal, functor) overload, leaving only 4/5 argument(s) overloads > QObject::connect(sender, signal, receiver/context, functor/slot, (type)) as well as the string-based connect(). The reason for NOT using the 3-args overload is that it is error prone. For starters, it makes it hard to reason about the lifetime of such a connection. It makes it very easy to connect to lambdas that capture some local state in the receiver, but when the receiver is destroyed, the connection isn't automatically disconnected (therefore, if the signal is emitted, the program will crash). Fixing this may or may not be straightforward, depending on how much state is captured. Second, it's also easy to forget that since there's no receiver/context, the connection is always forced to be *direct*, which complicates things if multiple threads are involved. -- I'm about to enable the macro for (most) of QtBase: https://codereview.qt-project.org/c/qt/qtbase/+/489232 I've also done the exercise of enabling it for qtdeclarative (patches pending) and qttools (merged), but there's simply too much code out there that *still* uses it. As I said above, fixes are not always obvious (sometimes it's very unclear who the "receiver" is). -- Since this is ultimately a code style issue, I'd like to leave the decision with the module maintainers regarding whether or not enable QT_NO_CONTEXTLESS_CONNECT for their own modules. Ideally, however, we should enable it in headersclean, so please make at least those not contain 3-args connect(). Opinions? Objections? Thank you, -- 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
-- Development mailing list Development@qt-project.org https://lists.qt-project.org/listinfo/development