将QComboBox :: currentIndexChanged(int)连接到QSignalMapper :: map()

时间:2015-01-31 18:07:19

标签: c++ qt signals mapper

我试图弄清楚如何在Qt5中实现这一目标:

connect(qcombobox, SIGNAL(currentIndexChanged(int),
        qsignalmappe, SLOT(map()));

我试过了:

connect(comboBox, static_cast<void(QComboBox::*)(int) (&QComboBox::currentIndexChanged),
        this->signalMapper, &QSignalMapper::map);

但编译器抱怨没有匹配的参数。我知道QSignalMapper :: map()信号没有参数,但我不知道它是如何使用旧语法的。

1 个答案:

答案 0 :(得分:3)

试试这个,它对我有用

 connect(comboBox,static_cast<void (QComboBox::*)(int index)>(&QComboBox::currentIndexChanged),signalMapper,static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));