Page 1 of 1

Signal overload

Posted: Tue Jul 02 2024 2:25 pm
by regon
Hi barbara,
how do I connect two overloaded signals to my application?

Example 1:
class QComboBox:{

GUI_CS_SIGNAL_1(Public, void currentIndexChanged(int index))
GUI_CS_SIGNAL_OVERLOAD(currentIndexChanged, (int), index)

GUI_CS_SIGNAL_1(Public, void currentIndexChanged(const QString &text))
GUI_CS_SIGNAL_OVERLOAD(currentIndexChanged, (const QString &), text)
};
Example 2:
class QAbstractSocket:{

SocketError error() const;

NET_CS_SIGNAL_1(Public, void error(QAbstractSocket::SocketError socketError))
NET_CS_SIGNAL_OVERLOAD(error, (QAbstractSocket::SocketError), socketError)
};

Re: Signal overload

Posted: Wed Jul 03 2024 8:12 am
by barbara
Here is an example to help explain how this works. The valueChanged() signal for QSpinBox has two overloads.

When calling connect() using method pointers, the second parameter is a pointer to the signal and the fourth parameter is a pointer to the slot. If either the signal or the slot is overloaded additional syntax will be required so the compiler knows which overload to use. By adding the cs_mp_cast<int> syntax the compiler now has enough information to select the correct overload. In this example the overload which accepts an int data type will be used.

Code: Select all

QSpinBox *spinBox = new QSpinBox;
QProgressBar *progressBar = new QProgressBar;
 
connect(spinBox, cs_mp_cast<int>(&QSpinBox::valueChanged), progressBar, &QProgressBar::setValue);
You may want to look over Journal entry #8 where we discussed this information.
https://journal.copperspice.com/?p=705

Barbara

Re: Signal overload

Posted: Wed Jul 03 2024 10:07 am
by regon
Thank you for your answer.

[ Moved new questions to another topic "Migrating VTK" ]