title: qt passing object to different class
body: <p><strong>EDIT</strong></p>
  <p>I am creating all objects initially when the program is started in my <em>dialog.cpp</em> and storing all QPixmaps in an array then picking a random one from them all. That random QPixmap I want to pass to my maintargets class and draw in the scene (which is also created in the dialog.cpp).</p>
  <p>//    dialog.cpp</p>
  <pre><code>#include &quot;dialog.h&quot;
  #include &quot;scene.h&quot;
  #include &quot;ui_dialog.h&quot;
  #include &quot;instructions.h&quot;
  #include &quot;settings.h&quot;
  #include &quot;highscore.h&quot;
  #include &quot;maintargets.h&quot;
  #include &lt;stdlib.h&gt;
   
  Dialog::Dialog(QWidget *parent) :
      QDialog(parent),
      ui(new Ui::Dialog)
  {
      ui-&gt;setupUi(this);
   
      // Create and configure scene
       scene = new Scene;
       scene-&gt;setBackgroundBrush(Qt::black);
       scene-&gt;setItemIndexMethod(QGraphicsScene::NoIndex);
       ui-&gt;graphicsView-&gt;setScene(scene);
       scene-&gt;setSceneRect(-200, -150, 400, 300);
       ui-&gt;graphicsView-&gt;setMouseTracking(true);
   
       QPixmap tankbase1(&quot;:/images/tankbase.jpg&quot;);
       ui-&gt;tankbaseplay1-&gt;setPixmap(tankbase1);
   
       //Store targets in array and random generator
       index = 0;
       main_targets[0] = QPixmap(&quot;:images/darkbluelogo.jpg)&quot;);
       main_targets[1] = QPixmap(&quot;:images/graylogo.jpg&quot;);
       main_targets[2] = QPixmap(&quot;:images/lightbluelogo.jpg&quot;);
       main_targets[3] = QPixmap(&quot;:images/limE.jpg&quot;);
       main_targets[4] = QPixmap(&quot;:images/pink.jpg&quot;);
       main_targets[5] = QPixmap(&quot;:images/purple.jpg&quot;);
       main_targets[6] = QPixmap(&quot;:images/redlogo.jpg&quot;);
       main_targets[7] = QPixmap(&quot;:images/yellow.jpg&quot;);
       main_targets[8] = QPixmap(&quot;:images/brown.jpg&quot;);
   
       index = qrand((index % 9) + 1);
   
       //scene-&gt;addItem(main_targets[index]);
   
   
       //Timer for scene advancement
       QTimer *timer = new QTimer();
       QObject::connect(timer, SIGNAL(timeout()), scene, SLOT(advance()));
       timer-&gt;start(100);
   
  }
   
  Dialog::~Dialog()
  {
      delete ui;
  }
  </code></pre>
  <p>//maintargets.h</p>
  <pre><code>#ifndef MAINTARGETS_H
  #define MAINTARGETS_H
  #include &quot;dialog.h&quot;
  #include &lt;QGraphicsItem&gt;
  #include &lt;QGraphicsScene&gt;
  #include &lt;QPainter&gt;
  #include &lt;QRect&gt;
   
  class MainTargets : public QGraphicsScene
  {
  public:
      MainTargets();
      QRectF boundingRect() const;
      QPainterPath shape() const;
      void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
   
  protected:
      void advance(int step);
   
  private:  
      qreal dx, dy;
      qreal x, y;
      qreal w, h;
       
  };
  
   
  #endif // MAINTARGETS_H
  </code></pre>
  <p>//maintargets.cpp</p>
  <pre><code>#include &quot;maintargets.h&quot;
  
  MainTargets::MainTargets()
  {
      dx = -0.005;
      dy = 0.0;
      x = 1.5;
      y = 0.0;
      w = 100.0;
      h = 70.0;
  
  }
  
  QRectF MainTargets::boundingRect() const
  {
      qreal shift = 1;
          return QRectF(-w/2 -shift, - h/2
                        - shift, w + shift, h + shift);
  }
  
  QPainterPath MainTargets::shape() const
  {
      QPainterPath path;
      path.addRect(boundingRect());
      return path;
  }
  
  void MainTargets::paint(QPainter *painter,
                          const QStyleOptionGraphicsItem *option,
                          QWidget *widget)
  {        
      painter-&gt;drawPixmap(-w/2, -h/2, main_targets[index]);
  }
  
  void MainTargets::advance(int step)
  {
      if(step == 0) return;
      x = x + dx;
      y = y + dy;
      setPos(mapToParent(x, y));
  }
  </code></pre>
  <p>After it is drawn it moves in x-direction.</p>