Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
QMetaType::registerConverter should be able to pass it's template parameters to a template custom converter function.
Implementation proposal:
A common usecase when passing around variant containers trough QProperties:
//Proposal template<typename From, typename To, template <typename ...> typename C>static bool registerConverter(C<From, To> function){ Q_STATIC_ASSERT_X((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn), "QMetaType::registerConverter: At least one of the types must be a custom type."); const int fromTypeId = qMetaTypeId<From>(); const int toTypeId = qMetaTypeId<To>(); static const QtPrivate::ConverterFunctor<From, To, C<From, To>> f(function); return registerConverterFunction(&f, fromTypeId, toTypeId); } //A template custom variant container to custom type container converter template <typename T> struct TemplateParameter; template <template <typename ...> typename C, typename T> struct TemplateParameter<C<T>> { using type = T; }; template <typename T> using type = typename TemplateParameter<T>::type; template <typename From, typename To>To fromSharedVariantContainer(const From &from){ To to; for(const auto& it : from){ to << qSharedPointerCast<type<To>>(it); } return to; } //Usecase https://github.com/semlanik/qtprotobuf/blob/master/src/protobuf/qqmllistpropertyconstructor.h Unusable pertinent methods