title: Understanding QScopedPointer passing by reference
body: <p>I've been trying to understand how to pass this as a const reference.  </p>
  
  <p>I have the following class: </p>
  
  <pre><code>class DBContext : public QObject
  </code></pre>
  
  <p>In my class MainWindow I define it as folows:</p>
  
  <pre><code>private:
      QScopedPointer&lt;DBContext&gt; dbContext;
  </code></pre>
  
  <p>How Storage class is defined:</p>
  
  <pre><code>class StorageData : public QObject
  {
      Q_OBJECT
  
  public:
      StorageData(QObject *parent = 0);
      ~StorageData();
  
      void SetDBContext(const QScopedPointer&lt;DBContext&gt; &amp;db_context);
  
  private:
      QScopedPointer&lt;DBContext&gt; dbContext;
  </code></pre>
  
  <p>In StorageData SetDBContext() I try to assign it with the following:</p>
  
  <pre><code>void StorageData::SetDBContext(const QScopedPointer&lt;DBContext&gt; &amp;db_context)
  {
      dbContext = db_context;
  }
  </code></pre>
  
  <p>Then in the MainWindow constructor initialize it:</p>
  
  <pre><code>dbContext.reset(new DBContext(this));
  StorageData storage;
  storage.SetDBContext(dbContext);
  </code></pre>
  
  <p>Using the following in StorageData function SetDBContext():</p>
  
  <pre><code>_DBContext = db_context; 
  </code></pre>
  
  <p>I get an error: </p>
  
  <p>'QScopedPointer>::operator =' : cannot access private member declared in class 'QScopedPointer>'</p>
  
  <p><strong>Update</strong></p>
  
  <p>Taking the tip of using QSharedPointer and QWeakPointer.  Is this a valid approach of using these two pointers?  Also am I using clear() correctly on both Class A &amp; B?</p>
  
  <pre><code>class A
  private:
    QWeakPointer&lt;DBContext&gt; dbContext;
  
  void A::~A()
  {
       dbContext.clear()
  }
  void A::SetDBContext(QWeakPointer&lt;DBContext&gt; db_context)
  {
      dbContext= db_context;
  }
  
  void A::UseCode()
  {
      QSharedPointer&lt;DBContext&gt; ptrContext= dbContext.toStrongRef();
      ..
  }
  
  class B constructor:
  private:
      QSharedPointer&lt;DBContext&gt; dbContext; 
  </code></pre>
  
  <p>In the constructor:</p>
  
  <pre><code>B::B()
  {
      dbContext.reset(new DBContext(this));
      QWeakPointer&lt;DBContext&gt; ptrDBConnect = dbContext;
      storage.SetDBContext(ptrDBConnect);
  }
  </code></pre>
  
  <p>In the destructor:</p>
  
  <pre><code>B::~B()
  {
      dbContext.clear();
  }
  </code></pre>