[Development] QMetaTypeId<void>::Defined illegal in Qt 5.5 beta

Roland Winklmeier roland.m.winklmeier at gmail.com
Sat May 16 11:12:48 CEST 2015

Hi all,

I was testing the Qt 5.5 beta binaries with my application and quickly
run into the following issue:

Short version:
The expression "QMetaTypeId<void>::Defined" seems to be no longer
allowed in 5.5. It is fine until 5.4.2 (or more precise until
Is this intended behaviour or an accepted source incompatibility since
QMetaTypeId is part of the private API?

Long Version:

Attached is a small example to reproduce the compiler error [1].

QMetaTypeId<T>::Defined is often used by users of Qt to write
conditional code. As far as I know it is the only method to find out at
compile time whether T was declared as Qt meta type or not. In the
project I'm working on, most of the classes have a common base class
CValueObject which helps with automatic registration as Qt Meta Type,
DBus Meta Type, etc. In here we are using some template magic
conditional on "QMetaTypeId< typename SomeMagic<T>::type>::Defined".
SomeMagic<T>::type defaults to void, if T does not fulfil specific type
requirements. Unfortunately, we cannot simply change the default to
void* without rewriting a lot.

I wonder if others will have the same problem with it. I didn't raise it
yet as QTBUG since I wasn't sure if this is part of the private API and
I have to accept it. But since there is no other official alternative to
QMetaTypeId<void>::Defined - at least known to me - would it be possible
to change the Qt header to make it compatible again?

Opinions, thoughts, advice?


[1] Compiler error:
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_CORE_LIB -I../metatype
-I. -I../../../Qt5.5.0/5.5/gcc_64/include
-I../../../Qt5.5.0/5.5/gcc_64/include/QtCore -I.
-I../../../Qt5.5.0/5.5/gcc_64/mkspecs/linux-g++ -o metatype_void.o
In file included from
                 from ../metatype/metatype_void.cpp:1:
../../../Qt5.5.0/5.5/gcc_64/include/QtCore/qmetatype.h: In instantiation
of 'struct QtPrivate::IsQEnumHelper<void>':
required from 'struct QMetaTypeId<void>'
../metatype/metatype_void.cpp:16:43:   required from here
../../../Qt5.5.0/5.5/gcc_64/include/QtCore/qmetatype.h:1377:25: error:
forming reference to void
         static const T &declval();
../../../Qt5.5.0/5.5/gcc_64/include/QtCore/qmetatype.h:1382:60: error:
'declval' was not declared in this scope
         enum { Value = sizeof(qt_getEnumMetaObject(declval())) ==
sizeof(QMetaObject*) };
Makefile:552: recipe for target 'metatype_void.o' failed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: metatype_void.cpp
Type: text/x-c++src
Size: 533 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20150516/40359bff/attachment.cpp>

More information about the Development mailing list