gpt4 book ai didi

c++ - 为什么 QVariant::type() 在应该被解释为 QMetaType::Type 时返回 QVariant::Type?

转载 作者:太空狗 更新时间:2023-10-29 23:01:01 27 4
gpt4 key购买 nike

关于 QVariant::type() 的文档说:

Returns the storage type of the value stored in the variant. Although this function is declared as returning QVariant::Type, the return value should be interpreted as QMetaType::Type. In particular, QVariant::UserType is returned here only if the value is equal or greater than QMetaType::User.

好吧,如果是这样,他们为什么不首先将其声明为返回 QMetaType::Type?这样看来只会带来不必要的困惑。

文档没有解释声明函数返回错误类型的原因,有人知道这些原因可能是什么吗?

最佳答案

首先是 QVariant,它带有一个支持类型的 type 枚举。然后 QMetaType 出现了,它有自己的 type 支持类型的枚举。

因此 QVariant 被更改,类型对齐,因此它自己的 type 枚举可以被弃用,并且它将依赖于 QMetaType 来获取类型信息。但是,出于源兼容性原因,无法更改返回类型。

Qt6 的返回类型可能会更改,但源代码不兼容的更改视情况而定,因此必须讨论更改的影响和好处。

关于c++ - 为什么 QVariant::type() 在应该被解释为 QMetaType::Type 时返回 QVariant::Type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32009630/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com