Why use QVector(Qt) instead of std::vector

后端 未结 6 1603
面向向阳花
面向向阳花 2020-12-13 12:31

I\'m very new to C++ and Qt, but I\'m very good at C#/Java.

The point is I like cross-platform, but I\'m confuse with Qt. Isn\'t std::vector already cro

6条回答
  •  遥遥无期
    2020-12-13 12:43

    Since no answer mentioned it, Qt containers, including QVector generally have a fuller API, which does enable a certain amount of extra convenience and reduces verbosity when compared to std::vector.

    QVector isn't really integrated into the Qt APIs, that role is taken by misfit QList, so it is not really a strong argument to use QVector for overall better compatibility with Qt APIs. Note that this might change for Qt 6, as the shortcomings of QList become more and more acknowledged.

    That being said, if you already depend on Qt for your application, it would make good sense to use QVector for the convenience. I presume that nobody is going to add such a bloated dependency as Qt just for a container or two. QVector is efficient and a solid performer, and will run without problems on any platform, supported by Qt.

    On the other hand, if you want to make a core logic API that is framework agnostic, it would be a good idea to develop it in standard C++ if possible, so you get something portable that isn't tied to a particular GUI framework so you can easily migrate it to a different one in the future if you need to.

提交回复
热议问题