我知道我们可以使用 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();
关于c++ - Qt信号映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28650088/