[Interest] Qt ownership model
Thiago Macieira
thiago.macieira at intel.com
Sun Jun 5 14:49:36 CEST 2016
Em sábado, 4 de junho de 2016, às 15:55:47 BRT, Антон Жилин escreveu:
> 3. Widgets without a parent are usually used with QSharedPointer:
> auto obj = QSharedPointer<MyObject>::create(...);
> -- Not so great, it is verbose and does not line up with standard library
All those class names and function names with capital letters don't line up
with the standard library, so the argument is not accepted.
> I propose to add two functions to standard library:
>
> template<typename T, typename... Args>
> QSharedPointer<T>
> QMakeShared(Args&&... args)
> {
> return QSharedPointer<T>::create(std::forward<Args>(args)...);
> }
Not going to add that.
> template<typename T, typename... Args>
> T*
> QMakeChild(Args&&... args)
> {
> static_assert(std::is_base_of<QObject, T>::value);
> static_assert(last of args is a QObject);
Except that for QWidgets, the parent is first, not last.
> return new T(std::forward<Args>(args)...);
> }
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Interest
mailing list