以下成員源於類 QWeakPointer 已過時。 提供它們是為使舊源代碼能繼續工作。強烈建議不要在新代碼中使用它們。
(obsolete)
|
QWeakPointer (const QObject * other ) |
(obsolete)
T *
|
data () const |
(obsolete)
QWeakPointer<T> &
|
operator= (const QObject * other ) |
此函數已過時。提供它是為使舊源代碼能繼續工作。強烈建議不要在新代碼中使用它。
Creates a QWeakPointer that holds a weak reference directly to the
QObject
other
. This constructor is only available if the template type
T
is
QObject
or derives from it (otherwise a compilation error will result).
You can use this constructor with any QObject , even if they were not created with QSharedPointer .
Note that QWeakPointers created this way on arbitrary QObjects usually cannot be promoted to QSharedPointer .
該函數在 Qt 4.6 引入。
另請參閱 QSharedPointer and QPointer .
此函數已過時。提供它是為使舊源代碼能繼續工作。強烈建議不要在新代碼中使用它。
使用 toStrongRef () instead, and data() on the returned QSharedPointer .
Returns the value of the pointer being tracked by this
QWeakPointer
,
without
ensuring that it cannot get deleted. To have that guarantee, use
toStrongRef
(), which returns a
QSharedPointer
object. If this function can determine that the pointer has already been deleted, it returns
nullptr
.
It is ok to obtain the value of the pointer and using that value itself, like for example in debugging statements:
qDebug("Tracking %p", weakref.data());
However, dereferencing the pointer is only allowed if you can guarantee by external means that the pointer does not get deleted. For example, if you can be certain that no other thread can delete it, nor the functions that you may call.
If that is the case, then the following code is valid:
// 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);
}
Use this function with care.
該函數在 Qt 4.6 引入。
另請參閱 isNull () 和 toStrongRef ().
此函數已過時。提供它是為使舊源代碼能繼續工作。強烈建議不要在新代碼中使用它。
Makes this
QWeakPointer
hold a weak reference directly to the
QObject
other
. This function is only available if the template type
T
is
QObject
or derives from it.
該函數在 Qt 4.6 引入。
另請參閱 QPointer .