在QT中是否有值的动态存储?
一个:
QDoubleArray x;
x.append(4.6);
x.append(4.8);
x.append(5.2);
//x.count() = 3
最佳答案
在QT中,QStringList是一个特例,它是唯一可以被视为通用容器特化的类型,如 QList<QString>
.它的存在主要是因为处理字符串列表是开发中的一个常见问题,因此它提供了一些 QList 没有的有用方法。
QT 文档通常建议使用 QList类:
QList<double> x;
x.push_back(4.6);
x.push_back(4.8);
x.push_back(5.2);
文档是这样说的:
For most purposes, QList is the right class to use. Its index-based API is more convenient than QLinkedList's iterator-based API, and it is usually faster than QVector because of the way it stores its items in memory. It also expands to less code in your executable.
If you need a real linked list, with guarantees of constant time insertions in the middle of the list and iterators to items rather than indexes, use QLinkedList.
If you want the items to occupy adjacent memory positions, use QVector.
关于c++ - 在 QT 中,是否有用于 double、float、int... 等的动态数组,即 QDoubleArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18085643/