Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-107052

QMetaType::registerConverter implementation should support custom template converter function

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Core: Other
    • 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
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            boxout cxv cvcv
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes