Obsolete Members for QWeakPointer
QWeakPointer 클래스의 다음 멤버는 더 이상 사용되지 않습니다. 이들은 이전 소스 코드의 작동을 유지하기 위해 제공됩니다. 새 코드에서는 사용하지 않는 것이 좋습니다.
공용 함수
(deprecated) | QWeakPointer(const QObject *other) |
(deprecated) T * | data() const |
(deprecated) QWeakPointer<T> & | operator=(const QObject *other) |
멤버 함수 문서
[deprecated]
QWeakPointer::QWeakPointer(const QObject *other)
이 함수는 더 이상 사용되지 않습니다. 새 코드에서는 사용하지 않는 것이 좋습니다.
QObject other 에 대한 약한 참조를 직접 보유하는 QWeakPointer를 생성합니다. 이 생성자는 템플릿 유형 T
이 QObject 이거나 이로부터 파생된 경우에만 사용할 수 있습니다(그렇지 않으면 컴파일 오류가 발생함).
이 생성자는 QSharedPointer 으로 생성되지 않았더라도 모든 QObject 과 함께 사용할 수 있습니다.
임의의 QObject에서 이런 식으로 생성된 QWeakPointers는 일반적으로 QSharedPointer 로 승격할 수 없습니다.
QSharedPointer 및 QPointer 을참조하십시오 .
[deprecated]
T *QWeakPointer::data() const
이 함수는 더 이상 사용되지 않습니다. 새 코드에서 이 함수를 사용하지 않는 것이 좋습니다.
대신 toStrongRef()를 사용하고 반환된 QSharedPointer 에 data()를 사용하세요.
이 QWeakPointer 에서 추적 중인 포인터의 값을 삭제되지 않도록 보장하지 않고 반환합니다. 이러한 보장을 받으려면 QSharedPointer 객체를 반환하는 toStrongRef()를 사용합니다. 이 함수가 포인터가 이미 삭제된 것을 확인할 수 있는 경우 nullptr
을 반환합니다.
예를 들어 디버깅 문에서와 같이 포인터의 값을 가져와서 그 값 자체를 사용하는 것은 괜찮습니다:
qDebug("Tracking %p", weakref.data());
그러나 포인터를 역참조하는 것은 포인터가 삭제되지 않았다는 것을 외부 수단을 통해 보장할 수 있는 경우에만 허용됩니다. 예를 들어, 다른 스레드나 호출할 수 있는 함수가 포인터를 삭제할 수 없다는 것을 확신할 수 있는 경우입니다.
이 경우 다음 코드가 유효합니다:
// this pointer cannot be used in another thread // so other threads cannot delete it QWeakPointer<int> weakref = obtainReference(); Object *obj = weakref.data(); if (obj) { // if the pointer wasn't deleted yet, we know it can't get // deleted by our own code here nor the functions we call otherFunction(obj); }
이 함수는 주의해서 사용하세요.
isNull() 및 toStrongRef()도 참조하세요 .
[deprecated]
QWeakPointer<T> &QWeakPointer::operator=(const QObject *other)
이 함수는 더 이상 사용되지 않습니다. 새 코드에서 이 함수를 사용하지 않는 것이 좋습니다.
QWeakPointer 이 QObject other 에 대한 약한 참조를 직접 보유하게 만듭니다. 이 함수는 템플릿 유형 T
이 QObject 이거나 이로부터 파생된 경우에만 사용할 수 있습니다.
QPointer도 참조하세요 .
© 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.