Results 1 to 2 of 2

Thread: Invoke common Signal for all objects of QVector

  1. #1
    Join Date
    Jun 2015
    Posts
    94
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Invoke common Signal for all objects of QVector

    Hello,

    I have create class of QwtPlotMagnifier,
    Qt Code:
    1. class ZoomMagnify: public QwtPlotMagnifier
    2. {
    3. Q_OBJECT
    4. public:
    5. ZoomMagnify(QwtPlot *plot, Qt::KeyboardModifier key);
    6.  
    7. private:
    8. virtual void rescale(double factor) override;
    9.  
    10. signals:
    11. void autoScaleDisable(bool state);
    12. };
    To copy to clipboard, switch view to plain text mode 

    Then I have create objects using QVector,
    Qt Code:
    1. QVector<ZoomMagnify*> magnifier;
    2. connect(magnifier.at(0), &ZoomMagnify::autoScaleDisable, m_checkBox, &QCheckBox::setChecked);
    3. connect(magnifier.at(1), &ZoomMagnify::autoScaleDisable, m_checkBox, &QCheckBox::setChecked);
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Invoke common Signal for all objects of QVector

    You can iterate over a vector in many ways.

    For example
    Qt Code:
    1. for (ZoomMagnify *zm : magnifier) {
    2. connect(zm, &ZoomMagnify::autoScaleDisable, m_checkBox, &QCheckBox::setChecked);
    3. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    npatil15 (20th February 2019)

Similar Threads

  1. Fatal Signal on invoke methode
    By patrikd in forum Qt Quick
    Replies: 2
    Last Post: 30th October 2014, 12:05
  2. Replies: 9
    Last Post: 27th March 2014, 09:45
  3. Replies: 3
    Last Post: 29th September 2013, 11:46
  4. Can QVector hold objects?
    By N3wb in forum Newbie
    Replies: 6
    Last Post: 14th April 2010, 20:29
  5. signal-slot problem with QVector
    By stefan in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2008, 13:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.