Task is to connect from one signal with one parameter to a slot with zero parameters. With the "old" Qt4-way of connect it works like this
connect(object1, SIGNAL(signal(int param)), object2, SLOT(slot()))
But what if I want to use the type-safe Qt5-connects?
The documentation just mentions the cases with:
connect to default parameters in slot
and using the above-mentioned way of the stringbased connect.
The Qt5-style connect mechanism ignores extra-arguments of the signal just like you could specify in the Qt4-style:
The signals and slots mechanism is type safe: The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.) Since the signatures are compatible, the compiler can help us detect type mismatches when using the function pointer-based syntax. The string-based SIGNAL and SLOT syntax will detect type mismatches at runtime.
From the Qt Docs (emphasis mine).
So you can use the new style like this:
connect(&object1, &ClassObject1::signal, &object2, &ClassObject2::slot);
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