引用自:http://www.ibm.com/developerworks/cn/linux/guitoolkit/qt/signal-slot/

的一篇经典文章,是关于Qt的信号和槽的分析的。看年份是2001年,有年头了。

其中:

7.信号与槽不能有缺省参数。

既然signal->slot绑定是发生在运行时刻,那么,从概念上讲使用缺省参数是困难的。下面的用法是不合理的:

class SomeClass : public QObject 
    {
        Q_OBJECT
    public slots:
        void someSlot(int x=100); // 将x的缺省值定义成100,在槽函数声明中使用是错误的
    };

是就目前来说是不正确的。

再看QThread源码:

public Q_SLOTS:
    void start(Priority = InheritPriority);
    void terminate();
    void quit();

其中start槽是有默认参数的。也许你会好奇Q_SLOTS是嘛东西?看看官方的解释吧:

Q_SLOTS

Use this macro to replace the slots keyword in class declarations, when you want to use Qt Signals and Slots with a 3rd party signal/slot mechanism.

从功能上来讲,宏Q_SLOTS和slots关键字是一样的。所以,Qt的槽应该可以使用默认参数。

相关文章:

  • 2022-12-23
  • 2021-09-24
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-07-07
  • 2021-12-05
相关资源
相似解决方案