Qt信号映射

Qt signal mapping

本文关键字:映射 信号 Qt      更新时间:2023-10-16

我知道我们可以使用QSignalMapper来收集一组无参数信号,并使用与发送信号的对象相对应的整数、字符串或小部件参数重新发送它们。

但我们可以反过来做吗?例如,是否可以实现:

connect(control,startVehicle(0),vehcileList[0],startReceived());
connect(control,startVehicle(1),vehcileList[1],startReceived());
connect(control,startVehicle(2),vehcileList[2],startReceived());

而不是将来自控制的3个不同信号作为

startVehicle_1();
startVehicle_2(); 
startVehicle_3();

有一种更简单的方法:

connect(control, SIGNAL(startVehicle(int)), this, SLOT(startReceived(i)));
//in startReceived(i) slot
vehcileList[i]->startReceived();