智能指针在Qt [英] Smart pointers in Qt

查看:242
本文介绍了智能指针在Qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像写了这里 Qt到现在有8个指定的智能指针类。
看起来这是所有你需要的。
然而,为了使用任何这些智能指针,您的类必须从QObject派生,这并不总是方便。
在Qt中是否有其他的智能指针实现可以使用任意类?

Like it has been written here Qt up to now has 8 specilized smart pointer classes. It looks like it is all you will ever need. However, in order to use any of these smart pointers your class must be derived from QObject which is not always convenient. Is there other implementations of smart pointers in Qt which work with arbitrary classes?

推荐答案

许多Qt类派生自QObject,虽然一些内置的智能指针类与QObject(或QSharedData)相关,但 QSharedPointer QScopedPointer 模板显示为允许指针指向任何内容。

Many Qt classes are derived from QObject, and while some of the built in smart pointer classes are related to QObject (or QSharedData), the QSharedPointer and QScopedPointer templates appear to allow pointers to anything.

除此之外,您还可以找到一些 Boost 中的智能指针模板:

Beyond that, you'll find some smart pointer templates in Boost:

  • scoped_ptr - Simple sole ownership of single objects. Noncopyable.
  • scoped_array - Simple sole ownership of arrays. Noncopyable.
  • shared_ptr - Object ownership shared among multiple pointers.
  • shared_array - Array ownership shared among multiple pointers.
  • weak_ptr - Non-owning observers of an object owned by shared_ptr.
  • intrusive_ptr - Shared ownership of objects with an embedded reference count.

这篇关于智能指针在Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆