Results 1 to 2 of 2

Thread: connect and widget index

  1. #1
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default connect and widget index

    Hi,

    I need to connect a changed signal of a QSpinBox, QDoubleSpinBox, and a QLineEdit member of a QWidget array with a on_Change slot, but I need to transmit also the index of a QWidegt.
    This code work fine (this for QSpinBox):

    Qt Code:
    1. connect(widget[index], SIGNAL(valueChanged(const QString &)), this, SLOT(on_Changed()));
    To copy to clipboard, switch view to plain text mode 

    but I want to send also the index, like this:

    Qt Code:
    1. connect(widget[index], SIGNAL(valueChanged(const QString &)), this, SLOT(on_Changed(const int &myindex)));
    To copy to clipboard, switch view to plain text mode 

    thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: connect and widget index

    Hi, take a look at QSignalMapper:
    Qt Code:
    1. QSignalMapper* mapper = new QSignalMapper(this);
    2. ...
    3. connect(widget[index], SIGNAL(valueChanged(const QString &)), mapper, SLOT(map()));
    4. mapper->setMapping(widget[index], index);
    5. ...
    6. connect(mapper, SIGNAL(mapped(int)), this, SLOT(on_Changed(int)));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    nowire75 (25th November 2007)

Similar Threads

  1. Dynamic QSplitter
    By EricF in forum Qt Programming
    Replies: 4
    Last Post: 26th October 2007, 14:59
  2. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

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.