[Development] QMetaType and type aliases for primitive types

Alberto Mardegan mardy at users.sourceforge.net
Sat May 8 09:48:51 CEST 2021


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

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".
2) QtDBus claims not to be able to marshal a "long"

I've being trying to understand why (1) happens: immediately as the
program starts, if I print the numeric ID of the "int64_t" type, I get 0
(which is fair, I guess).
Then I do

    qRegisterMetaType<int64_t>("int64_t");

and afterwards I see that its QMetaType ID is 32, but
QMetaType::typeName(32) returns "long". I tried using the
Q_DECLARE_METATYPE() and Q_DECLARE_TYPEINFO() macros, but in both cases
the compiler complains that the type is being redefined:

server.cpp:108:1: error: redefinition of 'struct QMetaTypeId<long int>'
 Q_DECLARE_METATYPE(int64_t);

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.

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?

Ciao,
  Alberto

-- 
http://www.mardy.it - Geek in un lingua international




More information about the Development mailing list