[Development] Is QImage movable

Knoll Lars Lars.Knoll at theqtcompany.com
Thu May 28 08:40:05 CEST 2015


On 26/05/15 13:56, "Marc Mutz" <marc.mutz at kdab.com> wrote:

>On Saturday 23 May 2015 19:47:28 Thiago Macieira wrote:
>> On Saturday 23 May 2015 15:35:23 Иван Комиссаров wrote:
>> > Hi.
>> > 
>> > I’ve created a QVector of QImages and tried to insert an image in the
>> > vector: QVector<QImage> images;
>> > images.insert(images.begin(), QImage());
>> > 
>> > I got a compiler warning saying
>> > 
>> > "qvector.h:649:21: warning: destination for this 'memmove' call is a
>> > pointer to dynamic class 'QImage'; vtable pointer will be overwritten
>> > [-Wdynamic-class-memaccess]»
>> > 
>> > This happens because QImage inherits QPaintDevice (which is virtual)
>>and
>> > QImage is declared movable using Q_DECLARE_SHARED macro.
>> > 
>> > Is this behavior intended?
>> 
>> Yes.
>
>In Qt 6, we should probably change that to static polymorphism. E.g.
>anything 
>with a
>  QPaintDevice * paintDevice()
>method on can be painted-to. I ran into the polymorphism of what should
>be a 
>value class, too, already (when implementing swap).

Static polymorphism could actually work nicely in this case, but it would
break source compatibility in some cases.

IRC, we couldn’t easily do it in Qt 4 when we added the inheritance as
templated member functions weren’t working on all compilers.

Cheers,
Lars




More information about the Development mailing list