[Interest] Re: qRegisterMetaType<QList<QSslError> > and type flags

Jan Kundrát jkt at flaska.net
Wed Feb 6 14:25:56 CET 2013


On Wednesday, 2 January 2013 17:42:53 CEST, Stephen Kelly wrote:
> Of course it's a bug and an odd mistake that 
> Q_DECLARE_METATYPE(QList<QSslError>) is in qsslsocket.h instead of 
> qsslerror.h. 

Hi Stephen,
using qtbase v5.0.0-320-ge17dddf, the following code fails to build:

$ cat test-qdeclaremetatype.cpp 
#include <QSslError>
Q_DECLARE_METATYPE(QList<QSslError>)
$ g++ -c -DQT_STRICT_ITERATORS -DQT_NETWORK_LIB -DQT_CORE_LIB -I/opt/qt5/mkspecs/linux-g++ -I/opt/qt5/include -I/opt/qt5/include/QtNetwork -I/opt/qt5/include/QtCore -o blah test-qdeclaremetatype.cpp 
test-qdeclaremetatype.cpp:2:1: error: redefinition of ‘struct QMetaTypeId<QList<QSslError> >’
/opt/qt5/include/QtNetwork/qsslerror.h:126:1: error: previous definition of ‘struct QMetaTypeId<QList<QSslError> >’

It worked fine with 4.x and 5.0.0.

What is the cleanest way out here? Shall I just check for a particular Qt version? Shall I use some template hackery to check whether the QMetaTypeId::Defined is zero?

Either way, in the actual code of my application, I'm also calling Q_DECLARE_METATYPE(QList<QSslCertificate>). This is not declared in any Qt header (yet). However, this mechanism seems rather fragile. One could possibly argue that the library itself shall use that for their own classes, but one has to draw the border somewhere; it is not reasonable to expect that the <QSslError> header will also delcare metatype data for QVector<QSslError>, QMap<QString,QSslError> etc etc. Yet, when it gets introduced, the existing user code no longer compiles.

What shall I use in my code to make sure that the metatype stuff is defined and also make the code reasonably future proof?

With kind regards,
Jan

-- 
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/



More information about the Interest mailing list