[Interest] QScopedPointer and c++11 move semantics

Nikos Chantziaras realnc at gmail.com
Sat Dec 31 14:09:13 CET 2016


On 12/30/2016 08:47 PM, Alexander Dyagilev wrote:
> Hello,
>
> https://bugreports.qt.io/browse/QTBUG-29754
>
> states that the problem was fixed and QScopedPointer supports it now.
>
> But it does not.
>
> std::move does not compile.
> error: C2248:
> 'QScopedPointer<WebPagesIterator,QScopedPointerDeleter<T>>::QScopedPointer':
> cannot access private member declared in class
> 'QScopedPointer<WebPagesIterator,QScopedPointerDeleter<T>>'
> with
> [
> T=WebPagesIterator
> ]
>
> Visual C++ 2015.
> Both c+11 and c+14 enabled in pro files.

I suggest rolling your own anyway. You can use your own 
std::make_unique-like template (like q_make_unique) which creates a 
unique_ptr with the correct deleter. This allows you to write:

   auto obj_p = q_make_unique<SomeQObjectDerivedClass>(parent);

without specifying the deleter every time. But I use std::make_unique 
for pretty much everything, which is why the above looks more natural to me.




More information about the Interest mailing list