Is there any way to prevent or discourage the use of the old Signal-Slot syntax from Qt4 in projects solely written in Qt5?
In our current project, there are no occurrences of the old syntax and I don't see any reason to support them either. Thus we want to disable it completely to prevent accidental use. Is this possible, e.g. by defining certain symbols in the .pro
files?
I know this should be possible with custom Linter rules but we don't have that centralized yet unfortunately.
//old way. should throw a compiler error or warning
connect(sender, SIGNAL(sig), receiver, SLOT(slt));
//new way
connect(sender, &Send::sig, receiver, &Rec::slt);
If you have a shared header file in the project that you can ensure will be included after QObject
, you can do this:
#define SIGNAL(x) static_assert(false, "String-based signal/slot syntax has been disabled in this project")
Same for SLOT
.
If you want to turn it into warning, check out this answer. I definitely agree with you that the string based syntax is a plague and shouldn't occur outside of uic
ed files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With