如何将不同的信号连接到 QT 上的同一个插槽?
how connect different signals to the same slot on QT?
我正在尝试将不同的信号连接到同一个插槽,如下所示:
connect(thread_notification,SIGNAL(signal1()),SIGNAL(signal2()),this,SLOT(slot()));
可能吗?
是的,这是可能的。
您可以通过简单地为要发送到插槽的每个信号编写一个连接语句来完成,例如:
connect(thread_notification, SIGNAL(signal1()), this, SLOT(slot()));
connect(thread_notification, SIGNAL(signal2()), this, SLOT(slot()));
...
connect(thread_notification, SIGNAL(signalN()), this, SLOT(slot()));
您可以遵循的另一种方法是使用 QSignalMapper,尤其是当信号的发送者是数组、列表或通常是对象的容器时,但这取决于发送者和发送的信号。你可以在这里找到解释 http://doc.qt.io/qt-4.8/qsignalmapper.html
我正在尝试将不同的信号连接到同一个插槽,如下所示:
connect(thread_notification,SIGNAL(signal1()),SIGNAL(signal2()),this,SLOT(slot()));
可能吗?
是的,这是可能的。 您可以通过简单地为要发送到插槽的每个信号编写一个连接语句来完成,例如:
connect(thread_notification, SIGNAL(signal1()), this, SLOT(slot()));
connect(thread_notification, SIGNAL(signal2()), this, SLOT(slot()));
...
connect(thread_notification, SIGNAL(signalN()), this, SLOT(slot()));
您可以遵循的另一种方法是使用 QSignalMapper,尤其是当信号的发送者是数组、列表或通常是对象的容器时,但这取决于发送者和发送的信号。你可以在这里找到解释 http://doc.qt.io/qt-4.8/qsignalmapper.html