QList vs QVector revisited

后端 未结 8 2174
天涯浪人
天涯浪人 2020-12-23 22:00

My question is basically when to choose QVector and when to choose QList as your Qt container. What I already know:

  1. Qt docs: QList cl
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-23 22:23

    Please note that this has completely changed in Qt6: https://www.qt.io/blog/qlist-changes-in-qt-6

    QVector and QList are unified and the model of QVector is used as the underlying implementation. This means that Qt 5 QList's extra level of indirection for generic types is now gone and elements are always directly stored in the allocated memory. QList is the real class, with implementation, while QVector is just an alias to QList. QList in Qt 6 supports optimised prepend. It may now shrink on elements removal without usage of reserve. And the size limit of 2GB is removed.

提交回复
热议问题