title: Qt connect signal to slot
body: <p>I have a main window class which contains a QSplitter widget (among other widgets). The contents of this splitter are populated by the widgets that are in another class.</p>
  
  <p>Inside this other Widgwt I have a layout with a QPushButton called test_btn added I also have a function defined in the header file under <code>public slots:</code> called test_function which has the corresponding code in the cpp file:</p>
  
  <pre><code>cout &lt;&lt; "Test!" &lt;&lt; endl;
  </code></pre>
  
  <p>I try and call this function using the following code:</p>
  
  <pre><code>connect(test_btn, SIGNAL(clicked()), SLOT(test_function()));
  </code></pre>
  
  <p>The widgets and buttons appear as expected in the application but when I click it nothing happens.</p>
  
  <p>If I add the same <code>connect</code> code to the main window it works (for calling a test function from the main window) i.e.</p>
  
  <pre><code>connect(cc_point.test_btn, SIGNAL(clicked()), SLOT(main_win_test_function()));
  </code></pre>
  
  <p>I cant call the test function from the other class unless I call it from the <code>main_win_test_function()</code></p>
  
  <p>I know I'm missing the 'receiver widget' from the connect statement, although it does work without it in the main window class and I don't get any errors when compiling.</p>
  
  <p>Do I need to define the parent or something in the <code>other_class</code>?</p>
  
  <p>main_window.cpp:</p>
  
  <pre><code>main_window::main_window()
  {
      add_splitter();
  
      QGridLayout *window_layout = new QGridLayout;
  
      window_layout-&gt;setSpacing(0);
      window_layout-&gt;setContentsMargins(0, 0, 0, 0);
  
      window_layout-&gt;addWidget(splitter1, 0, 0);
  
      set_layout(window_layout);
  }
  
  void main_window::add_splitter()
  {
       other_class oc_point;
  
       splitter1 = new QSplitter(Qt::Horizontal);
  
       splitter1-&gt;addWidget(oc_point.oc_widget);
  }
  </code></pre>
  
  <p>other_class.cpp:</p>
  
  <pre><code>other_class:other_class()
  {
       oc_widget = new QWidget;
  
       QGridLayout *other_layout = new QGridLayout(oc_widget);
  
       test_btn = new QPushButton;
       test_btn-&gt;setText("Test Button");
  
       connect(test_btn, SIGNAL(clicked()), test_btn-&gt;parent(), SLOT(test_function());
       other_layout-&gt;addWidget(test_btn);
  }
  
  void other_class::test_function()
  {
       cout &lt;&lt; "Test output" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>int main(int argc, char *argv[]) {
  
  QApplication app(argc, argv);
  
  main_window window;
  
  window.resize(1100, 700);
  window.setWindowTitle("Qt Test");
  window.setWindowIcon(QIcon (":/images/icon_1.png"));
  window.setMinimumHeight(500);
  window.show();
  
  return app.exec();
  }
  </code></pre>
  
  <p>As I mentioned above, this all works fine as far as the window getting created and the widgets being displayed goes, but the test_function doesn't get called when I click the button. Let me know if I need to include my header files as well.</p>