title: Signal not declared in this scope/undefined reference to class::method
body: <p>I've been trying to sort out a custom signal in my Qt application, and I can't seem to get it to compile. Essentially I have a window with a slot to handle a button press (slotCalibrate()), and another slot to receive messages and output them to the screen via a QTextEdit (slotMessage()). Both of these functions work fine in isolation.</p>
  
  <p>Here is Window.cpp, slotCalibrate() is currently sending prefabricated data to Output class. In the final design slotCalibrate() will activate a calibration process on some hardware, and the results of that will be the data sent to Output.cpp</p>
  
  <pre><code>#include "window.h"
  #include "output.h"
  #include &lt;QPushButton&gt;
  #include &lt;QTextEdit&gt;
  #include &lt;QApplication&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  Window::Window(QWidget *parent) :
      QWidget(parent)
  {
      setFixedSize(640, 480);
  
      calButton = new QPushButton("Calibrate", this);
      calButton-&gt;setGeometry(280, 20, 80, 30);
      calButton-&gt;setToolTip("Press to zero connected transducers.");
  
      connect(calButton, SIGNAL(clicked()), this, SLOT(slotCalibrate()));
  
      quitButton = new QPushButton("Quit", this);
      quitButton-&gt;setGeometry(550, 440, 80, 30);
  
      connect(quitButton, SIGNAL(clicked()), QApplication::instance(), SLOT(quit()));
  
      readout = new QTextEdit(this);
      readout-&gt;setReadOnly(1);
      readout-&gt;setPlainText("Testing, testing, 1, 2, 3.\n");
      readout-&gt;setGeometry(10, 70, 620, 360);
  }
  
  void Window::slotCalibrate()
  {
      string sn[5] = {"1234", "2463", "7821", "5027", "5981"};
      Output *op = new Output();
      op-&gt;writeMessage(1, 5, sn);
      //I also tried the following with exactly the same result
      //Output op;
      //op.writeMessage(1, 5, sn);
  }
  
  void Window::slotMessage(string message)
  {
      QString qstr = QString::fromStdString(message); //Convert from string to QString
      readout-&gt;append(qstr);                          //Print message to screen
  }
  </code></pre>
  
  <p>I'm trying to get the button press to call the constructor of output.cpp, and then call the function writeMessage to construct and emit a message to slotMessage in window.cpp</p>
  
  <pre><code>#include "output.h"
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  
  using namespace std;
  
  Output::Output(QWidget *parent) :
      QWidget(parent)
  {
      connect (this, SIGNAL(sendMessage(string)), parentWidget(), SLOT(slotMessage(string)));
  }
  
  //void sendMessage(string)
  //{
  
  //}
  
  void writeMessage(int cat, int count, string sn[])
  {
      int i;
      stringstream ss;
      switch (cat)
      {
          case 1 : //Case where calibration of one or more nodes was successful
              ss &lt;&lt; count &lt;&lt; " transducers were successfully calibrated.\n Their serial numbers are:";
              for (i=0; i&lt;cat; i++)
              {
                  ss &lt;&lt; "\n" &lt;&lt; sn[i];
              }
              break;
          case 2:  //Case where calibration of one or more nodes failed
              ss &lt;&lt; "One or more transducers failed to calibrate.";
              break;
          case 3:  //Case where no config file is found
              ss &lt;&lt; "WARNING! Could not find 'params.config'. The default values will be used for calibration.";
                    break;
      }
      emit sendMessage(ss.str());
  }
  </code></pre>
  
  <p>Unfortunately, with the code exactly like this, the compiler shouts at me. It says:
  <code>'sendMessage' was not declared in this scope</code></p>
  
  <p>I have declared <code>sendMessage</code> in the header file as a signal, and I was under the impression signals didn't need to be implemented in code.</p>
  
  <p>Nevertheless, I decided to try implementing an empty function called <code>sendMessage</code>. This got rid of the compiler error, but introduced another error. When calling <code>op.writeMessage()</code> in window.cpp, I get the error:
   "undefined reference to `Output::writeMessage(int, int, std::string*)'"</p>
  
  <p>I have also tried calling <code>writeMessage</code> inside the Output constructor, and I get the same error.</p>
  
  <p>I am thoroughly lost, and have been working on this issue for a couple of days now, so any help would be immensely appreciated.</p>
  
  <p>For completeness here are the header files window.h and output.h respectively:</p>
  
  <p>window.h</p>
  
  <pre><code>#ifndef WINDOW_H
  #define WINDOW_H
  
  #include &lt;QWidget&gt;
  #include &lt;string&gt;
  
  class QPushButton;
  class QTextEdit;
  class Window : public QWidget
  {
      Q_OBJECT
  public:
      explicit Window(QWidget *parent = 0);
      QTextEdit *readout;
  private:
      QPushButton *calButton;
      QPushButton *quitButton;
  
  signals:
  
  public slots:
      void slotCalibrate();
  
  private slots:
      void slotMessage(std::string);
  };
  
  #endif // WINDOW_H
  </code></pre>
  
  <p>output.h</p>
  
  <pre><code>#ifndef OUTPUT_H
  #define OUTPUT_H
  
  #include &lt;QWidget&gt;
  #include &lt;QObject&gt;
  #include &lt;string&gt;
  
  class Output : public QWidget
  {
      Q_OBJECT
  public:
      explicit Output(QWidget *parent = 0);
      void writeMessage(int, int, std::string[]);
  signals:
      void sendMessage(std::string);
  public slots:
  
  };
  
  #endif // OUTPUT_H
  </code></pre>