title: Qt - Right Way to Implement Custom Signals and Slots
body: <p>I have one MainWindow and one Class; I want to send data between them using custom signal and slot. I can't seem to figure it out, I need help.</p>
  
  <p>Here is my code:
  MainWindow.h</p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;iostream&gt;
  #include "receive.h"
  QT_BEGIN_NAMESPACE
  namespace Ui { class MainWindow; }
  QT_END_NAMESPACE
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  
  public:
      MainWindow(QWidget *parent = nullptr);
      ~MainWindow();
  signals:
      void sendit(QString name);
  private slots:
      void on_send_button_clicked();
      void display(QString e)
      {        
       std::cout&lt;&lt;"Here is where I am called this "&lt;&lt;e.toStdString()&lt;&lt;std::endl;
      }
  
  private:
      Ui::MainWindow *ui;
  
  };
  #endif // MAINWINDOW_H
  </code></pre>
  
  <p>MainWindow.cpp</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include "receive.h"
  
  MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent)
      , ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);    
     Receive *r = new Receive();
     connect(this, SIGNAL(sendit(QString)), r, SLOT(display(QString)));
  
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  
  void MainWindow::on_send_button_clicked()
  {
      emit sendit(ui-&gt;lineEdit-&gt;text());
  
  }
  </code></pre>
  
  <p>receive.h</p>
  
  <pre><code>#ifndef RECEIVE_H
  #define RECEIVE_H
  
  #include &lt;iostream&gt;
  #include &lt;QDialog&gt;
  
  class Receive : public QDialog
  {
  public:
      Receive();
  private slots:
      void display(QString e);
  };
  
  #endif // RECEIVE_H
  </code></pre>
  
  <p>receive.cpp</p>
  
  <pre><code>#include "receive.h"
  #include "mainwindow.h"
  
  Receive::Receive()
  {
  
  }
  
  void Receive::display(QString e)
  {    
   std::cout&lt;&lt;"Here is where I am called this "&lt;&lt;e.toStdString()&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>When I run this program, I get this message:</p>
  
  <p>06:26:29: Starting C:\Users\Troy\Documents\build-tests-Desktop_Qt_5_14_1_MinGW_32_bit-Debug\tests.exe ...
  QObject::connect: No such slot QDialog::display(QString) in ..\tests\mainwindow.cpp:11
  QObject::connect:  (sender name:   'MainWindow')</p>
  
  <p>How do I get this done, please?</p>
  
  <p>Thank  you for your help.</p>