QSignalMapper and original Sender()

前端 未结 2 1187
滥情空心
滥情空心 2021-01-14 02:43

I have a bunch of QComboBoxes in a table. So that I know which one was triggered I remap the signal to encode the table cell location (as described in Selecting

2条回答
  •  旧巷少年郎
    2021-01-14 03:42

    Why not connect the QComboBox's signal straight to your slot?

    QComboBox *combo = ...
    connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changedType(int)));
    

    And then in your slot you can use the sender() method to retrieve the QComboBox that was changed.

    void myDlg::changedType(int row)
    {
        QComboBox *combo = qobject_cast sender();
    
        if(combo != 0){
            // rest of code
        }
    }
    

    Alternatively, to use the QSignalMapper method you would just need to change your slot to use the mapping you set up:

    void myDlg::changedType(int row)
    {
        QComboBox *combo = qobject_cast(_signalMapper->mapping(row));
    
        if(combo != 0){
            // rest of code
        }
    }        
    

提交回复
热议问题