QExplicitlySharedDataPointer Class
template <typename T> class QExplicitlySharedDataPointerQExplicitlySharedDataPointer 클래스는 명시적으로 공유된 객체에 대한 포인터를 나타냅니다. 더 보기...
| 헤더: | #include <QExplicitlySharedDataPointer> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| 상속: | QSharedDataPointerBase |
참고: 이 클래스의 모든 함수는 재진입 가능합니다.
QExplicitlySharedDataPointer 비교
| 범주 | 비교 가능한 유형 |
|---|---|
| strong | QExplicitlySharedDataPointer |
| strong | T* 및 std::nullptr_t. |
공개 유형
공개 함수
| QExplicitlySharedDataPointer() | |
| QExplicitlySharedDataPointer(T *data) | |
| QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<X> &o) | |
| QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o) | |
| QExplicitlySharedDataPointer(QExplicitlySharedDataPointer<T> &&o) | |
| ~QExplicitlySharedDataPointer() | |
| const T * | constData() const |
| T * | data() const |
| void | detach() |
(since 6.0) T * | get() const |
(since 6.0) void | reset(T *ptr = nullptr) |
| void | swap(QExplicitlySharedDataPointer<T> &other) |
| T * | take() |
| operator bool() const | |
| bool | operator!() const |
| T & | operator*() const |
| T * | operator->() |
| T * | operator->() const |
| QExplicitlySharedDataPointer<T> & | operator=(QExplicitlySharedDataPointer<T> &&other) |
| QExplicitlySharedDataPointer<T> & | operator=(T *o) |
| QExplicitlySharedDataPointer<T> & | operator=(const QExplicitlySharedDataPointer<T> &o) |
보호된 함수
| T * | clone() |
관련 비회원 요소
| bool | operator!=(const QExplicitlySharedDataPointer<T> &lhs, const QExplicitlySharedDataPointer<T> &rhs) |
| bool | operator!=(const T *const &lhs, const QExplicitlySharedDataPointer<T> &rhs) |
| bool | operator==(const QExplicitlySharedDataPointer<T> &lhs, const QExplicitlySharedDataPointer<T> &rhs) |
| bool | operator==(const T *const &lhs, const QExplicitlySharedDataPointer<T> &rhs) |
상세 설명
QExplicitlySharedDataPointer는 템플릿 매개변수 T 가 QSharedData 에서 파생된 공유 데이터 클래스의 유형을 지정하는 템플릿 클래스입니다.
QExplicitlySharedDataPointer<T>를 사용하면 명시적으로 공유되는 사용자 정의 클래스를 쉽게 작성할 수 있습니다. QExplicitlySharedDataPointer는 스레드 안전 참조 카운팅을 구현하여, 재진입 가능한 클래스에 QExplicitlySharedDataPointer를 추가하더라도 해당 클래스가 재진입 불가능해지지 않도록 보장합니다.
한 가지 큰 차이점을 제외하면, QExplicitlySharedDataPointer는 QSharedDataPointer 와 똑같습니다. 그 큰 차이점은, QExplicitlySharedDataPointer의 멤버 함수는 공유 데이터 객체의 수정을 허용하기 전에 QSharedDataPointer 의 비const 멤버가 수행하는 자동 복사 쓰기 작업(detach())을 수행하지 않는다는 것입니다. detach() 함수가 제공되지만, 정말로 detach()를 수행하려면 직접 호출해야 합니다. 즉, QExplicitlySharedDataPointer는 일반 C++ 포인터와 유사하게 동작하지만, 참조 카운팅을 수행하고 참조 카운트가 0이 될 때까지 공유 데이터 객체를 삭제하지 않음으로써 매달린 포인터(dangling pointer) 문제를 방지한다는 점이 다릅니다.
예제를 통해 QExplicitlySharedDataPointer와 QSharedDataPointer 를 비교해 보면 도움이 됩니다. QSharedDataPointer 에 있는 Employee example 를 살펴보세요. 이 예제는 Implicit vs Explicit Sharing 의 논의에서 설명된 대로 명시적 공유를 사용하도록 수정되었습니다.
이 클래스를 사용 중인데 detach()을 자주 호출하고 있다면, 대신 QSharedDataPointer 를 사용하는 것이 더 나을 것입니다.
멤버 함수 문서에서 d 포인터는 항상 공유 데이터 객체를 가리키는 내부 포인터를 의미합니다.
QSharedData 및 QSharedDataPointer도 참조하십시오 .
멤버 함수 설명서
[noexcept] QExplicitlySharedDataPointer::QExplicitlySharedDataPointer()
nullptr 로 초기화된 QExplicitlySharedDataPointer 객체를 d 포인터로 생성합니다.
[explicit noexcept] QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(T *data)
d 포인터를 ` data `로 설정하고, ` data`의 참조 횟수를 1 증가시킨 `QExplicitlySharedDataPointer` 객체를 생성합니다.
[noexcept] template <typename X> QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<X> &o)
이 복사 생성자는 ` o `가 명시적으로 공유된 데이터 포인터의 다른 유형이더라도, 호환되는 공유 데이터 객체를 가지는 경우를 허용한다는 점에서 다릅니다.
기본적으로 o 의 d 포인터 ( \a X * 형)는 \a T * 형으로 암시적으로 변환되며, 이 변환의 결과가 this의 d 포인터로 설정되고 공유 데이터 객체의 참조 횟수가 증가합니다.
[noexcept] QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o)
이 표준 복사 생성자는 `this `의 `d` 포인터를 ` o ` 내의 ` d` 포인터로 설정하고, 공유 데이터 객체의 참조 횟수를 1 증가시킵니다.
[noexcept] QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(QExplicitlySharedDataPointer<T> &&o)
QExplicitlySharedDataPointer 인스턴스를 Move 방식으로 생성하여, 이 인스턴스가 o 가 가리키던 것과 동일한 객체를 가리키게 합니다.
QExplicitlySharedDataPointer::~QExplicitlySharedDataPointer()
공유 데이터 객체의 참조 횟수를 1 감소시킵니다. 참조 횟수가 0이 되면 공유 데이터 객체가 삭제되며, 이후 해당 객체는 소멸됩니다.
[protected] T *QExplicitlySharedDataPointer::clone()
현재 데이터의 딥 카피를 생성하여 반환합니다. 이 함수는 참조 카운트가 1보다 클 때 detach()에 의해 호출되어 새로운 복사본을 생성합니다. 이 함수는 new 연산자를 사용하며, T 유형의 복사 생성자를 호출합니다.
사용 방법에 대한 설명은 QSharedDataPointer<T>::clone()을 참조하십시오.
[noexcept] const T *QExplicitlySharedDataPointer::constData() const
공유 데이터 객체에 대한 const 포인터를 반환합니다.
data()도 참조하십시오 .
[noexcept] T *QExplicitlySharedDataPointer::data() const
공유 데이터 객체에 대한 포인터를 반환합니다.
void QExplicitlySharedDataPointer::detach()
공유 데이터 객체의 참조 횟수가 1보다 크면, 이 함수는 공유 데이터 객체의 심층 복사본을 생성하고, 이 객체의 d 포인터를 해당 복사본으로 설정합니다.
QExplicitlySharedDataPointer 는 QSharedDataPointer 의 멤버 함수들이 수행하는 ‘쓰기 시 자동 복사(copy-on-write) ’ 작업을 수행하지 않기 때문에, 이 클래스의 멤버 함수 내 어디에서도 detach()가 자동으로 호출되지 않습니다. 코드 전반에 걸쳐 detach()를 호출하고 있는 경우, 대신 QSharedDataPointer 를 사용하는 것을 고려해 보십시오.
[noexcept, since 6.0] T *QExplicitlySharedDataPointer::get() const
data()와 동일합니다. 이 함수는 STL 호환성을 위해 제공됩니다.
이 함수는 Qt 6.0에서 도입되었습니다.
[noexcept, since 6.0] void QExplicitlySharedDataPointer::reset(T *ptr = nullptr)
ptr 가 nullptr 가 아닌 경우, 이 객체의 d 포인터를 ptr 로 설정하고 ptr 의 참조 횟수를 1 증가시킵니다. 기존 공유 데이터 객체의 참조 횟수는 1 감소하며, 참조 횟수가 0이 되면 해당 객체는 삭제됩니다.
이 함수는 Qt 6.0에서 도입되었습니다.
[noexcept] void QExplicitlySharedDataPointer::swap(QExplicitlySharedDataPointer<T> &other)
other 와 이 명시적으로 공유된 데이터 포인터를 교환합니다. 이 작업은 매우 빠르며 절대 실패하지 않습니다.
[noexcept] T *QExplicitlySharedDataPointer::take()
공유 객체에 대한 포인터를 반환하고, `this`를 ` nullptr`로 재설정합니다. (즉, 이 함수는 `this `의 `d` 포인터를 ` nullptr`로 설정합니다.)
참고: 반환된 객체의 참조횟수는 감소되지 않습니다. 이 함수는 ` QAdoptSharedDataTag ` 태그 객체를 인수로 받는 생성자와 함께 사용하여, 원자적 연산을 거치지 않고 공유 데이터 객체를 전송할 수 있습니다.
[noexcept] QExplicitlySharedDataPointer::operator bool() const
이 객체의 d 포인터가 null이 아닐 경우 true 를 반환합니다.
[noexcept] bool QExplicitlySharedDataPointer::operator!() const
이 객체의 d 포인터가 ` nullptr`인 경우 ` true `를 반환합니다.
T &QExplicitlySharedDataPointer::operator*() const
공유 데이터 객체의 멤버에 대한 접근을 제공합니다.
[noexcept] T *QExplicitlySharedDataPointer::operator->()
공유 데이터 객체의 멤버에 대한 액세스 권한을 제공합니다.
[noexcept] T *QExplicitlySharedDataPointer::operator->() const
공유 데이터 객체의 멤버에 대한 const 접근을 제공합니다.
[noexcept] QExplicitlySharedDataPointer<T> &QExplicitlySharedDataPointer::operator=(QExplicitlySharedDataPointer<T> &&other)
other 를 이 QExplicitlySharedDataPointer 인스턴스에 할당합니다.
[noexcept] QExplicitlySharedDataPointer<T> &QExplicitlySharedDataPointer::operator=(T *o)
이 객체의 d 포인터를 o 로 설정하고, o 의 참조 횟수를 1 증가시킵니다. 이 객체의 기존 공유 데이터 객체의 참조 횟수는 1 감소합니다. 기존 공유 데이터 객체의 참조 횟수가 0이 되면, 해당 객체는 삭제됩니다.
[noexcept] QExplicitlySharedDataPointer<T> &QExplicitlySharedDataPointer::operator=(const QExplicitlySharedDataPointer<T> &o)
이 객체의 d 포인터를 o 의 d 포인터로 설정하고, 공유 데이터 객체의 참조 횟수를 1 증가시킵니다. 이 객체의 기존 공유 데이터 객체의 참조 횟수는 1 감소합니다. 기존 공유 데이터 객체의 참조 횟수가 0이 되면, 해당 객체는 삭제됩니다.
관련 비멤버 변수
[noexcept] bool operator!=(const QExplicitlySharedDataPointer<T> &lhs, const QExplicitlySharedDataPointer<T> &rhs)
lhs 와 rhs 가 동일한 d 포인터를 가리키지 않는 경우, true 를 반환합니다.
[noexcept] bool operator!=(const T *const &lhs, const QExplicitlySharedDataPointer<T> &rhs)
rhs 의 d 포인터가 lhs 가 아닐 경우, true 를 반환합니다.
[noexcept] bool operator==(const QExplicitlySharedDataPointer<T> &lhs, const QExplicitlySharedDataPointer<T> &rhs)
lhs 와 rhs 가 동일한 d 포인터를 가리키는 경우, true 를 반환합니다.
[noexcept] bool operator==(const T *const &lhs, const QExplicitlySharedDataPointer<T> &rhs)
rhs 의 d 포인터 가 lhs 인 경우 true 를 반환합니다.
© 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.