PDA

View Full Version : [SOLVED] connect overloaded signal with parameter



Al_
2nd May 2014, 07:58
Hi

I prefer to use the more modern signal/slot connect() version as it is typesafe at run-time. Copied from the Qt documentation: "QObject::connect(lineEdit, &QLineEdit::textChanged, label, &QLabel::setText);". How is this done when there are overloaded functions and/or signals?

Examples:

"connect(camera, &QCamera::error, this, &CaptureDialog::errorSlot);" does not compile because there are two QCamera::error functions: the signal "QCamera::error(QCamera::Error)" and the regular function "QCamera::error() const"
"connect(camera, &QCamera::lockStatusChanged, this, &CaptureDialog::lockStatusChangedSlot);" does not compile because there are two signals QCamera::lockStatusChanged with different parameters

anda_skoa
2nd May 2014, 09:41
I prefer to use the more modern signal/slot connect() version as it is typesafe at run-time.

Even the old connects are typesafe at runtime. What you probably meant is typesafe/typechecked at compile time.



Examples:

"connect(camera, &QCamera::error, this, &CaptureDialog::errorSlot);" does not compile because there are two QCamera::error functions: the signal "QCamera::error(QCamera::Error)" and the regular function "QCamera::error() const"
"connect(camera, &QCamera::lockStatusChanged, this, &CaptureDialog::lockStatusChangedSlot);" does not compile because there are two signals QCamera::lockStatusChanged with different parameters


You need to provide disambiguation through casting



connect(camera, static_cast<void(QCamera::*)(QCamera::Error)>(&QCamera::error), this, &CaptureDialog::errorSlot);


Cheers,
_

Al_
2nd May 2014, 10:27
Great, thanks for quick reply. Works perfectly! I had played around with QMetaMethod, had tried to typedef; but casting did not come to my mind.

PS: yes, I meant compile time.