本页内容

QScopedArrayPointer Class

template <typename T, typename Cleanup> class QScopedArrayPointer

QScopedArrayPointer 类存储指向一个动态分配的对象数组的指针,并在销毁时将其删除。更多内容...

头文件: #include <QScopedArrayPointer>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
继承自: QScopedPointer

注意:本类中的所有函数均为可重入函数。

公共函数

QScopedArrayPointer()
QScopedArrayPointer(D *p)
~QScopedArrayPointer()
T &operator[](qsizetype i)
const T &operator[](qsizetype i) const

详细说明

QScopedArrayPointer 是一个QScopedPointer ,默认会使用 delete[] 运算符删除其所指向的对象。模板参数T 指定数组元素的类型,而可选参数Cleanup 指定清理处理程序。它还提供了 operator[] 以方便使用,因此我们可以这样编写:

void foo()
{
    QScopedArrayPointer<int> i(new int[10]);
    i[2] = 42;
    ...
    return; // our integer array is now deleted using delete[]
}

成员函数文档

QScopedArrayPointer::QScopedArrayPointer()

构建一个 QScopedArrayPointer 实例。

[explicit] template <typename D, QScopedArrayPointer<T, Cleanup>::if_same_type<D> = true> QScopedArrayPointer::QScopedArrayPointer(D *p)

构建一个 QScopedArrayPointer,并将p 所指向的对象数组存储其中。

[default] QScopedArrayPointer::~QScopedArrayPointer()

销毁QScopedArrayPointer 的实例。

T &QScopedArrayPointer::operator[](qsizetype i)

提供对作用域指针所指向的对象数组中第i 个元素的访问。

如果所包含的指针是nullptr ,则行为未定义。

注意:在 Qt 6.5 之前的版本中,i 的类型为int ,而非qsizetype ,这可能会在 64 位平台上导致截断。

另请参阅 isNull()。

const T &QScopedArrayPointer::operator[](qsizetype i) const

提供对作用域指针所指向的对象数组中第i 个元素的访问权限。

如果包含的指针是nullptr ,则行为未定义。

注意:在 Qt 6.5 之前的版本中,i 的类型为int ,而非qsizetype ,这可能会在 64 位平台上导致截断。

另请参阅 isNull()。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.