c++ - 在 QT 中,是否有用于 double、float、int... 等的动态数组,即 QDoubleArray?

标签 c++ qt

在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/

相关文章:

c++ - 我们如何并行运行算法的 n 个实例并以有效的方式计算结果函数的平均值?

c++ - 这是操纵 C++ 容器元素的正确方法吗?

c++ - Qt 对话框如何从函数中触发 accept() 和 reject()

windows - Windows XP 和 GetTickCount64 上的 Qt 应用程序

c++ - '../controlpanel.ui' 需要 Qt : No rule to make target 'ui_controlpanel.h' ,。停止

c++ - 模板编程的可维护性建议和最佳实践

c++ - 使用循环(不是迭代器)从 vector 中删除指针

C++ map 性能 - Linux(30 秒)与 Windows(30 分钟)!

javascript - 在 QML 中访问 QList 对象

c++ - 使用 Windows 函数 SendMessage 导致与 MSVC 的链接错误,但与 MinGW 的链接错误