Details
-
Suggestion
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
None
-
None
Description
The registerConverter function fails when I am trying extend the core conversion(s).
The fail is caused by the static assert. Commit: f7b313e6d86
"QMetaType::registerConverter: At least one of the types must be a custom type."
My proposal:
Allow to extend the conversions.
Pre-check before registration with: QMetaType::hasRegisteredConverterFunction
// member function as in "QString QFont::toString() const" template<typename From, typename To> static bool registerConverter(To(From::*function)() const) { bool registerConverterResult = false; const int fromTypeId = qMetaTypeId<From>(); const int toTypeId = qMetaTypeId<To>(); const bool hasRegisteredConverterFunction = QMetaType::hasRegisteredConverterFunction(fromTypeId, toTypeId); if (hasRegisteredConverterFunction == true) { static const QtPrivate::ConverterMemberFunction<From, To> f(function); registerConverterResult = QMetaType::registerConverterFunction(&f, fromTypeId, toTypeId); } return registerConverterResult; } // member function as in "double QString::toDouble(bool *ok = nullptr) const" template<typename From, typename To> static bool registerConverter(To(From::*function)(bool*) const) { bool registerConverterResult = false; const int fromTypeId = qMetaTypeId<From>(); const int toTypeId = qMetaTypeId<To>(); const bool hasRegisteredConverterFunction = QMetaType::hasRegisteredConverterFunction(fromTypeId, toTypeId); if (hasRegisteredConverterFunction == true) { static const QtPrivate::ConverterMemberFunction<From, To> f(function); registerConverterResult = QMetaType::registerConverterFunction(&f, fromTypeId, toTypeId); } return registerConverterResult; } // functor or function pointer template<typename From, typename To, typename UnaryFunction> static bool registerConverter(UnaryFunction function) { bool registerConverterResult = false; const int fromTypeId = qMetaTypeId<From>(); const int toTypeId = qMetaTypeId<To>(); const bool hasRegisteredConverterFunction = QMetaType::hasRegisteredConverterFunction(fromTypeId, toTypeId); if (hasRegisteredConverterFunction == true) { static const QtPrivate::ConverterFunctor<From, To, UnaryFunction> f(function); registerConverterResult = QMetaType::registerConverterFunction(&f, fromTypeId, toTypeId); } return registerConverterResult; }
My conversion were the following ones:
QString -> QBitArray
QBitArray -> QString
OR
QByteArray-> QBitArray
QBitArray -> QByteArray