You are right that QSharedPointer is a little overhead for the reasons indicated.
Unfortunately, Qt does not have such a pointer vector, and it is also a little doubtful whether to add it when the language develops, and we have good primitives for doing such tasks.
I just had a quick discussion with one of the Qt core developers, and it seems like the recommended solution for today is QSharedPointer or this is from C ++ 11:
std::vector<std::unique_ptr<AbstractClass>>
Do not try to use QVector instead of std :: vector, as QVector may want to make copies.
Do not try to use this solution even in C ++ 11:
QList<QScopedPointer<AbstractClass>>
The problem is that QList wants to make copies. When using any non-constant method, detach is called, which makes copies, and this will not be a compiler.
In addition, QScopedPointer does not have constructors or movement operators, and which are by design .
lpapp source share