c++ - Qt信号映射

标签 c++ qt

我知道我们可以使用 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/

相关文章:

c++ - BOOST_FOREACH 宏强制方法脱离 Visual Studio 命名空间

c++ - 自动将int转换为unsigned int

c++ - 用c++同时读写同一个文件

c++ - 在 C++ 中将整数移动到最接近的可被 4 整除的位置

c++ - Qt 用例将相同信号发送到同一对象上的 2 个插槽?

Qt 控制台应用程序 : while loop blocks event loop

c++ - Qt:如何让mainWindow在centralwidget调整大小时自动调整大小?

c++ - QMake 与 GCC 的链接问题

c++ - 服务器内存管理

第三方 API 的 C++ #include - 永远找不到一些 header