[Development] Would it make sense to make QObject moveable in Qt 6?

Marc Mutz marc.mutz at kdab.com
Thu Aug 25 11:48:07 CEST 2016


On Wednesday 24 August 2016 20:05:56 Kuba Ober wrote:
> `QObject` is already pretty much a handle to the underlying data due to
> pimpl. So that’s a good first step.

I challenge the notion that QObject is a handle to date.

QObject is first and foremost the base class of a polymorphic class hierarchy.

If you wrap that in a parallel value-like-but-not-quite class hierarchy, you 
end up with QDomNode. I don't like QDomNode. Do you like QDomNode?

That said, the Copperspice guys argue that the implicit memory management of 
QObject parent-child relationships is becoming alien for C++ developers. The 
Qt community can of course deny every claim that comes from that direction, 
but sometimes the look of an outsider is valuable, too. After all, the API 
quality matters most for newbies, not decade-long Qt users.

So IMO, it's certainly worth asking the question whether we should change 
something there, e.g. by using shared_ptr/weak_ptr to manage lifetimes.

That would cover your use-case:

   std::vector<std::shared_ptr<QObject>>

is all you were asking for. And wether you then use shared_ptr explicitly, or

   template <typename Object>
   using QObjectHandle = std::shared_ptr<Object>;

is pretty much secondary.

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - Qt, C++ and OpenGL Experts



More information about the Development mailing list