[Development] QMetaType and non-const references
Volker Hilsheimer
volker.hilsheimer at qt.io
Tue Jul 19 20:45:29 CEST 2022
> On 19 Jul 2022, at 18:08, Thiago Macieira <thiago.macieira at intel.com> wrote:
>
>> Lastly, an aside: Q_DECLARE_METATYPE being effectively unnecessary was the
>> goal for Qt 6, but is not the case yet. I consider that a bug that should
>> finally be fixed in 6.5.
>
> Right. There should be exactly one use for Q_DECLARE_METATYPE: when the name
> you want to register is not the name that the C++ language recognises for your
> type, and this should only be done for legacy reasons.
>
> typedef QMap<int, int> IntMap;
> Q_DECLARE_METATYPE(IntMap);
>
> And you may have the string "IntMap" somewhere in your meta objects.
Interestingly,
qDe0bug() << QMetaType::fromType<std::string>().name();
qDebug() << QMetaType::fromName("std::string");
prints, with Apple clang:
std::__1::basic_string<char>
QMetaType()
but with msvc 22:
std::basic_string<char,std::char_traits<char>,std::allocator<char>>
QMetaType()
and then "std::string" in your meta object won’t work either, I suppose?
But interestingly, neither does
Q_DECLARE_METATYPE(std::string).
With
qRegisterMetaType<std::string>(“std::string”);
I get
std::__1::basic_string<char>
QMetaType(std::__1::basic_string<char>)
with clang and
td::basic_string<char,std::char_traits<char>,std::allocator<char>>
QMetaType(std::basic_string<char,std::char_traits<char>,std::allocator<char>>)
with msvc 22. What does that mean if e.g. "std::string" is present in a meta object?
> Any opinion on what must happen together or not at all?
I agree with Fabian, it seems uncontroversial to treat T& and T as different types in the QMetaType system. Code that relies on them being the same needs to be fixed anyway. Doing that doesn’t seem to prevent anything else discussed.
Volker
More information about the Development
mailing list