[SOLVED] connect overloaded signal with parameter
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
Re: connect overloaded signal with parameter
Quote:
Originally Posted by
Al_
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.
Quote:
Originally Posted by
Al_
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
Code:
connect(camera, static_cast<void(QCamera::*)(QCamera::Error)>(&QCamera::error), this, &CaptureDialog::errorSlot);
Cheers,
_
Re: connect overloaded signal with parameter
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.