[Development] QMetaType and type aliases for primitive types

Thiago Macieira thiago.macieira at intel.com
Sat May 8 17:47:11 CEST 2021

On Saturday, 8 May 2021 00:48:51 PDT Alberto Mardegan wrote:
> Hi there!
>   I'm struggling to understand what's going on with types being
> marshalled onto D-Bus, and I'd like to understand if what I'm seeing is
> a but with the Qt version I'm using (Qt 5.12.7 + some patches), an issue
> with the compiler, or just the expected behaviour.
> The problem is that QtDBus fails to send some messages:
> QDBusMarshaller: type `long' (32) is not registered with D-BUS. Use
> qDBusRegisterMetaType to register it

Qt doesn't like long. This has nothing to do with QtDBus.

Don't use long.

> What happens is that I'm creating a QVariant and writing a int64_t
> inside it, and for some reason:
> 1) QMetaType resolves that to "long", so the QVariant ends up holding a
> "long", and not a "int64_t".

Correct. So don't use long. Use qint64, which is a long long.

> I'm not sure how to proceed. I really would like to continue using the
> standard C types, because they are part of a D-Bus API and their length
> should not change depending on the CPU architecture.

Yeah, this is the problem.

And the problem is that they *do* depend on the CPU architecture. long changes 
size depending on OS and pointer size. 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.

It gets even worse: on some architectures, ptrdiff_t can be neither int32_t 
nor int64_t, despite matching the size of one of those two; ditto for size_t 
and/or uintptr_t versus uint32_t and uint64_t.

> 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.

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

More information about the Development mailing list