【问题标题】:how connect different signals to the same slot on QT?如何将不同的信号连接到 QT 上的同一个插槽?
【发布时间】:2016-10-21 20:14:27
【问题描述】:

我正在尝试将不同的信号连接到同一个插槽,如下所示:

connect(thread_notification,SIGNAL(signal1()),SIGNAL(signal2()),this,SLOT(slot()));

有可能吗?

【问题讨论】:

    标签: qt4


    【解决方案1】:

    是的,这是可能的。 您可以通过简单地为要发送到插槽的每个信号编写一个连接语句来做到这一点,例如:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-07
      • 1970-01-01
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      相关资源
      最近更新 更多