title: Connect and pass data between widget and mainwindow
body: <p>I want to pass data between MainWindow and Widget where I draw graph.
  In MainWindow I load a data, do few things and create dynamic array.</p>
  
  <ol>
  <li>I need to pass this array from mainwindow to widget to draw a graph.</li>
  <li>In widget file I have a function that works, when I click a button in MainWindow</li>
  </ol>
  
  <p>I don't know how to do this between two files mainwindow.cpp and drawwidget.cpp</p>
  
  <p>This is my Code:</p>
  
  <p>mainwindow.cpp:</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include &lt;QFileDialog&gt;
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
  }
  
  MainWindow::~MainWindow()
  {
      wyczyscpkt(Tab_pkt);
      wyczysc(Tab_we);
      delete ui;
  }
  </code></pre>
  
  <p>mainwindow.h:</p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  
  namespace Ui {
  class MainWindow;
  }
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();
  
  signals:
  
  
  private slots:
  void on_saveimageButton_clicked();
      //other functions
  
  public slots:
  
  private:
      Ui::MainWindow *ui;
      //my functions
  
   public slots:
  
  };
  
  #endif // MAINWINDOW_H
  </code></pre>
  
  <p>drawwidget.cpp:</p>
  
  <pre><code>DrawWidget::DrawWidget(QWidget *parent) :
      QWidget(parent)
  {
  
  }
  
  void DrawWidget::paint(QPainter &amp;painter, struct *myarray) //here I need pass array from mainwindow.cpp
  {
   //drawing function
  }
  void DrawWidget::savePng()
  {
   //save image function
  }
  </code></pre>
  
  <p>drawwidget.h:</p>
  
  <pre><code>#ifndef DRAWWIDGET_H
  #define DRAWWIDGET_H
  
  #include &lt;QWidget&gt;
  #include "mainwindow.h"
  
  
  class DrawWidget : public QWidget
  {
      Q_OBJECT
  public:
      explicit DrawWidget(QWidget *parent = 0);
  
  protected:
      void paintEvent(QPaintEvent *);
      void paint(QPainter &amp;painter);
      void savePng();
  
  };
  
  #endif // DRAWWIDGET_H
  </code></pre>