title: How to check for existence of a pointer before delete in qt
body: <p>I am using a <code>QAbstractTableModel</code>. The model holds data in it. It is created and deleted upon user clicks. </p>
  
  <p>This is the connected slot after user click to create a model:</p>
  
  <pre><code>void clicked(){
      model = new QAbstractTableModel(data);
      model-&gt;setManyThings();
  }
  </code></pre>
  
  <p>This is the connected slot after user click to clear the model:</p>
  
  <pre><code>void clear(){
      if (model != nullptr)
          delete model;
  }
  </code></pre>
  
  <p>However, this cannot check whether <code>model</code> is exist. If I click clear twice the program crash directly. If the model was not created be I click clear, the program crashed directly.</p>
  
  <p>So how to check whether model exist</p>