0

Recently Qt had made some changes and we can't semantically move QScopedPointer so we can't have a QList< QScopedPointer< SomeClass> > , based on my other question.

My second solution was using QScopedArrayPointer. But we cannot use these containers for abstract classes, which was my original problem. Is there any other way to use some list of QScopedPointer for abstract classes?

Community
  • 1
  • 1
e3oroush
  • 3,045
  • 1
  • 17
  • 26
  • Why won't you switch to `QSharedPointer` if what you need is not possible with `QScopedPointer`? – ixSci May 14 '16 at 10:39
  • I actually did use a QSharedPointer for my problem, but I'm seeking for a more best solution! because conceptually a QScopedPointer is sufficient for my problem and I don't want a QSharedPointer. – e3oroush May 14 '16 at 10:59
  • ok, but you can't use `QScopedPtr` as you already found out. So you don't have many choices. You can use raw pointers if the objects you store there are inherited from `QObject` — just pass a parent to them and you are done. Or, you can switch to `std::vector`. – ixSci May 14 '16 at 11:04
  • so, I think it's a bug or a loss for Qt. Because I think concept of QScopedPointer should allow us to have a QList >, but it seems not. – e3oroush May 14 '16 at 11:44
  • @JonHarper no I don't think it's for deleter function. Because of Q_DISABLED_COPY, we can't copy QList of QSCopedPointer!! – e3oroush May 14 '16 at 11:45
  • You can call it a drawback but it is certainly not a bug. Anyway, you are not forced to use it so if it doesn't suit your needs just switch to another solution. – ixSci May 14 '16 at 11:48
  • @JonHarper Yeah you right, thank you :) – e3oroush May 14 '16 at 11:50
  • Move semantics have been discussed before. It's pedantic, but the decision was made not to add them because it goes against the name and original intent of `QScopedPointer`. It would be nice if the devs would add a `QUniquePointer` (and deprecate `QScopedPointer` at Qt6). – jonspaceharper May 14 '16 at 12:03
  • I see that was discussed in an answer to your question. Oops. – jonspaceharper May 14 '16 at 12:36

0 Answers0