最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Why does QCheckBox::stateChanged signal sends an `int` instead of the dedicated `Qt::CheckState`? - Stack Overflow

programmeradmin2浏览0评论

Qt defines an enumeration Qt::CheckState which is used (for instance) by QCheckBox::checkState and QCheckBox::setCheckState.

What is surprising/confusing is that Qt defines the signal QCheckBox::stateChanged with an int argument instead of a Qt::CheckState, forcing us to lose the Qt::CheckState semantic when we want to define a slot to connect to this signal, which is quite annoying and makes the enumeration a bit useless.

Is there any rational behind such a decision or is this a Qt blunder ?

Qt defines an enumeration Qt::CheckState which is used (for instance) by QCheckBox::checkState and QCheckBox::setCheckState.

What is surprising/confusing is that Qt defines the signal QCheckBox::stateChanged with an int argument instead of a Qt::CheckState, forcing us to lose the Qt::CheckState semantic when we want to define a slot to connect to this signal, which is quite annoying and makes the enumeration a bit useless.

Is there any rational behind such a decision or is this a Qt blunder ?

Share Improve this question edited Apr 3 at 8:48 Fareanor asked Mar 31 at 12:10 FareanorFareanor 6,8132 gold badges15 silver badges45 bronze badges 6
  • Qt4 had it as an int too so probably historical reasons. – Botje Commented Mar 31 at 12:13
  • "Why does QCheckBox::stateChanged signal sends an int instead of the dedicated Qt::CheckState?" - You have to ask the creators/implementors of Qt that - have you tried that? – Jesper Juhl Commented Mar 31 at 12:15
  • @JesperJuhl Last time I opened an issue to Qt, it never was addressed and only the community (users) cared about it :) Hence why I'm asking the community first. – Fareanor Commented Mar 31 at 12:22
  • @Botje In that case, this is blunder/oversight from Qt – Fareanor Commented Mar 31 at 12:24
  • DoesQt::CheckState have a meta data? If not then queued connections for such signal would not work. – Marek R Commented Mar 31 at 13:06
 |  Show 1 more comment

1 Answer 1

Reset to default -1

According to the QT documentation, they focus on their slot-signal mechanism to be type safe:

The signature of a signal must match the signature of the receiving slot.

Making signal's signature dependent on specific enum will not be vesratile enough in some situation, especially when taking into account the everlasting problem of backward compatibility

发布评论

评论列表(0)

  1. 暂无评论