QScopedArrayPointer Class

template <typename T, typename Cleanup = QScopedPointerArrayDeleter<T>> class QScopedArrayPointer

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

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

注意:该类中的所有函数都是可重入的

公共函数

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

详细描述

QScopedArrayPointer 是一个QScopedPointer ,默认使用 delete[] 操作符删除指向的对象。为方便起见,它还具有 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 指向的对象数组。

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

提供对范围指针对象数组入口i 的访问。

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

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

另请参阅 isNull()。

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

提供对范围内指针对象数组入口i 的访问。

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

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

另请参阅 isNull()。

© 2025 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.