title: C++ / Qt Class Initialization
body: <p>I'm new to C++ and I'm trying to find the proper way to initialize this class.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>void NewDialog::createNew()
  {
      InkSpot *ink;
      ink = new InkSpot(this);
      InkPuppet *puppet;
      puppet-&gt;ui-&gt;canvas-&gt;addWidget(ink-&gt;widget);
      close();
  }
  </code></pre>
  
  <p>Now, for <code>InkSpot *ink;</code> &amp; <code>ink = new InkSpot(this);</code> it works fine because I actually DO need a new InkSpot created.</p>
  
  <p>But I do not need a new <code>InkPuppet *puppet</code> created, I simply need to refer to it's UI. Using the above code <code>puppet-&gt;ui-&gt;canvas-&gt;addWidget(ink-&gt;widget);</code> causes the program to crash because it is not being initialized.</p>
  
  <p>The whole issue here is, that to initialize a new class I know how to do it, but initializing a pre-existing class I'm not sure how to refer to it.</p>
  
  <p><strong>newdialog.h</strong></p>
  
  <pre><code>#ifndef NEWDIALOG_H
  #define NEWDIALOG_H
  
  #include "inkspot.h"
  #include "inkpuppet.h"
  #include "ui_inkpuppet.h"
  
  #include &lt;QDialog&gt;
  
  namespace Ui {
  class NewDialog;
  }
  
  class NewDialog : public QDialog
  {
      Q_OBJECT
  
  public:
      explicit NewDialog(QWidget *parent = 0);
      ~NewDialog();
      InkPuppet *pointerToPuppet;
  
  private:
      Ui::NewDialog *ui;
  
  private slots:
      void createNew(InkPuppet *existingPuppet);
  
  };
  
  #endif // NEWDIALOG_H
  </code></pre>
  
  <p><strong>inkpuppet.h</strong></p>
  
  <pre><code>#ifndef INKPUPPET_H
  #define INKPUPPET_H
  
  #include "inkspot.h"
  #include "ui_inkpuppet.h"
  
  #include &lt;QMainWindow&gt;
  #include &lt;QWidget&gt;
  
  namespace Ui {
  class InkPuppet;
  }
  
  class InkPuppet : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit InkPuppet(QWidget *parent = 0);
      ~InkPuppet();
  
      Ui::InkPuppet *ui;
  
  private slots:
      void setMinimum(int value);
      void setMaximum(int value);
      void actionNew();
      void actionAbout();
      void testButton();
  };
  
  #endif // INKPUPPET_H
  </code></pre>