title: Access UI elements from another class c++
body: <p>I have a problem with accessing ui elements from another class(with instance). I have a second QMainWindow in my application, I can access in secondWindow.cxx class all ui elements but not in read.cxx class. My code looks like following. Where is my mistake? Thank you for your help.</p>
  
  <pre><code>-------------------------------secondWindow.h------------------------------------
  
  #ifndef __secondWindow_h
  #define __secondWindow_h
  
  #include "ui_secondwindow.h"
  
  class secondWindow : public QMainWindow
  {
      friend class read;
      igstkStandardClassBasicTraitsMacro(secondWindow, QMainWindow);
      Q_OBJECT
  
  public:
      igstkStateMachineMacro();
  
      secondWindow();
      virtual ~secondWindow();
      void createSignalAndSlots();
  
  public slots:
      void secondWindowTest();
  
  protected:
  
  private:
      Ui::secondMainWindow m_secondWindowUI;
  };
  #endif
  
  -------------------------------secondWindow.cxx------------------------------------
  
  #include "secondWindow.moc"
  #include "secondWindow.h"
  #include "read.h"
  
  secondWindow::secondWindow() :m_StateMachine(this)
  {
      m_secondWindowUI.setupUi(this);
      createSignalAndSlots();
  }
  
  void secondWindow::createSignalAndSlots()
  {
      connect(m_secondWindowUI.pushButton1, SIGNAL(clicked()),this, SLOT(secondWindowTest()));
  
      connect(m_secondWindowUI.pushButton2, SIGNAL(clicked()), read::instance(), SLOT(readTest()));
  }
  
  void secondWindow::secondWindowTest()
  {
      m_secondWindowUI.pushButton1-&gt;setEnabled(true); //OK
  }
  
  secondWindow::~secondWindow(){}
  
  
  ---------------------------------read.h--------------------------------------
  
  #pragma once
  
  #include "secondWindow.h"
  
  class read : public QObject
  {
      Q_OBJECT
  
  public:
      static read *instance();
      read();
      virtual ~read() {}
  
  public slots:
      void readTest();
  
  protected:
      secondWindow    *m_readUI;
      static read     *m_read;
  
  private:
  };
  
  ---------------------------------read.cxx--------------------------------------
  #include &lt;read.moc&gt;
  #include "secondWindow.h"
  #include "read.h"
  
  read *read::m_read= NULL;
  
  read::read()
  {
      m_readUI = dynamic_cast&lt;secondWindow*&gt;( QApplication::instance() );
  }
  
  read *read::instance()
  {
      if(m_read == NULL)
      m_read = new read();
  
      return m_read;
  }
  
  void read::readTest()
  {
      m_readUI-&gt;m_secondWindowUI.qlabelTest-&gt;setText("test"); //segmentation fault
  }
  </code></pre>