[Development] Converting types in Qt

Jędrzej Nowacki jedrzej.nowacki at digia.com
Wed Jul 16 10:31:05 CEST 2014


On Tuesday 15 of July 2014 11:59:03 Olivier Goffart wrote:
> >      1.3 Should we try to support a user's type conversions out of the
> >box? 
> >          Currently a user needs to manually register a conversion function
> >
> > so Qt can know it and use it. For certain types we can do much better,
> >
> > because we can automatically convert some types. For example:
> >          QVector<char> -> QLinkedList<int>
> >          QList<Foo> -> QVector<Foo>
> >          QPointer<Foo> -> QObject*
> >          QPointer<Foo> -> void*
> >          QSharedDataPointer<Foo> -> bool
> >          MyQObject* -> QPointer<MyQObject>
> >          Currently we are not doing it for one reason which is behavior
> >
> > compatibility. What if a user already defined a conversion that we want to
> > add? It could happen because the conversion was not available in a
> > previous
> > Qt version. The problem is that the new conversion function may behave in
> > a
> > different way, especially in edge cases and because of the lack of
> > perfection mentioned in 1.2. We need to pick only one function. That could
> > be the Qt version, but then we risk that an existing code will not work
> > anymore. Are we willing to accept that?
> >
> >          I believe that we should document the problem, and allow the
> >
> > conversions.
> 
> I think we could try to automatically do conversion when we know how to do
> it.  And if there is an user defined conversion, it overrides the automatic
> one.

We could implement overriding, but we would not control which conversion is 
registered first / last. Moreover it would mean that a conversion could change 
at any point. I think it would be a bit too nondeterministic.

Cheers,
  Jędrek



More information about the Development mailing list