PDA

View Full Version : Invoke common Signal for all objects of QVector



npatil15
20th February 2019, 11:21
Hello,

I have create class of QwtPlotMagnifier,

class ZoomMagnify: public QwtPlotMagnifier
{
Q_OBJECT
public:
ZoomMagnify(QwtPlot *plot, Qt::KeyboardModifier key);

private:
virtual void rescale(double factor) override;

signals:
void autoScaleDisable(bool state);
};

Then I have create objects using QVector,

QVector<ZoomMagnify*> magnifier;
connect(magnifier.at(0), &ZoomMagnify::autoScaleDisable, m_checkBox, &QCheckBox::setChecked);
connect(magnifier.at(1), &ZoomMagnify::autoScaleDisable, m_checkBox, &QCheckBox::setChecked);

Now as we see I have to write 2 connect methods for both the objects to connect autoScaleDisable, so does it is possible I can write it in single connect method ?

Thanks

anda_skoa
20th February 2019, 12:59
You can iterate over a vector in many ways.

For example


for (ZoomMagnify *zm : magnifier) {
connect(zm, &ZoomMagnify::autoScaleDisable, m_checkBox, &QCheckBox::setChecked);
}


Cheers,
_