zoukankan      html  css  js  c++  java
  • QPointer很大程度上避免了野指针(使用if语句判断即可,类似于dynamic_cast),而且使用非常方便 good

    QPointer

    如何翻译呢?我不太清楚,保留英文吧。

    • The QPointer class is a template class that provides guarded pointers   to QObjects.

    • 使用:一个guarded指针,QPointer<T> ,行为和常规的指针 T * 类似

    • 特点:当其指向的对象(T必须是QObject及其派生类)被销毁时,它会被自动置NULL.
      • 注意:它本身析构时不会自动销毁所guarded的对象
    • 用途:当你需要保存其他人所拥有的QObject对象的指针时,这点非常有用

    一个例子

         QPointer<QLabel> label = new QLabel;
         label->setText("&Status:");
         ...
         if (label)
             label->show();

    如果在...部分你将该对象delete掉了,label会自动置NULL,而不会是一个悬挂(dangling)的野指针。

    QPointer 属于Qt Object模型的核心机制之一,请注意和其他智能指针的区别。

    http://blog.csdn.net/wsh6759/article/details/7432200

  • 相关阅读:
    cookie 和 session 和 session id
    getMasterRequest VS getCurrentRequest?
    drupal 7 watchdog 记录debug信息
    刷环境
    再进一步
    7zip 不见 .git
    为什么我记不住密码
    www / publish
    behat debug / class property
    drupal 网站Log
  • 原文地址:https://www.cnblogs.com/findumars/p/5614449.html
Copyright © 2011-2022 走看看