[Development] QMetaType and type aliases for primitive types

Thiago Macieira thiago.macieira at intel.com
Sun May 9 17:10:15 CEST 2021


On Saturday, 8 May 2021 23:55:36 PDT Alberto Mardegan wrote:
> yes, I knew that long changes size depending on the architecture, but:
> > As far as I am concerned, the fact that
> > int64_t, size_t and ptrdiff_t sometimes (not always!) use long is a
> > misfeature. Those decisions were made in the early 90s by C, before long
> > long existed in the standard, and before C++ with overloads and ABI
> > became an important thing. So we carry some legacy.
> 
> what I didn't know (or wasn't fully aware of the consequences) is that
> the {,u}intX_t types are just typedefs.

The only basic _t that wasn't a typedef is wchar_t and even then there used to 
be a switch on MSVC to make it a typedef, to keep compatibility with even 
older code.

Now we have char8_t, char16_t and char32_t too.

All the others are typedefs:
 - size_t
 - ptrdiff_t
 - (u)intptr_t
 - (u)intXX_t
 - (u)int_leastXX_t
 - (u)int_fastXX_t <-- don't use these at all
 - (u)intmax_t

The new C++ types are actual types: std::nullptr_t, std::align_val_t, 
std::byte, etc.

> >> Interestingly, I'm seeing this on amd64 only; it seems that on armhf
> >> everything is working fine. Could it be a bug with the compiler?
> > 
> > No, that's because there the compiler defines int64_t as a different type
> > (long long) because long is only 32-bit.
> 
> I see, now it makes sense. It looks like so far I managed to workaround
> the problem by changing int64_t to qint64 in a handful of places only,
> and changing the metatype registration to:
> 
>    qRegisterMetaType<qint64>("int64_t");
>    qRegisterMetaType<quint64>("uint64_t");
> 
> which makes Q_PROPERTY use the right type when I declare them as
> int64_t. Though maybe I'll eventually get rid of int64_t completely...

We can add marshalling for long in QtDBus, but like for QDataStream, we would 
serialise what the types currently are, but we can't guess what type you were 
actually using. Especially, we wouldn't be able to deal with long as an actual 
type across a program boundary.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering





More information about the Development mailing list