Which class should be used to connect a signal ?
-
Hi,
As far as I know, the following lines should be equivalent :
QObject::connect(ui->button, &QPushButton::clicked, this, []() {}); QObject::connect(ui->button, &QAbstractButton::clicked, this, []() {});Most examples and Qt sources tends to favor the first using the actual widget class. Does it make any difference ? And if there are, what are the benefits/drawbacks of both ?
The second makes code less susceptible to UI changes (replacing QPushButton with QRadioButton for example), and in any case, if the class/method doesn't match, it would result in a build error. I don't know if this is even possible, but the derived class could hide the signal from the base class causing issues, no ?
Thank you in advance !
-
@Tudal said in Which class should be used to connect a signal ?:
Does it make any difference ?
No, use what you like. I mostly use the class of the pointer before since I don't care in which base class the signal or slot is defined.