Qt: Symbol undefined when inheriting from QObject
<p>I'm new to Qt and tried to compile an example from the Qt pages (<a href="http://doc.qt.io/qt-4.8/signalsandslots.html" rel="nofollow">http://doc.qt.io/qt-4.8/signalsandslots.html</a>) that implements a simple class with a signal and a slot. Both when using Qt Creator and qmake by itself I get the following error message: </p>

<blockquote>
  <p>Undefined symbols for architecture x86_64:<br>
  "Counter::valueChanged(int)", referenced from:
        Counter::setValue(int) in main.o
        _main in main.o   "vtable for Counter", referenced from:
        _main in main.o</p>
</blockquote>

<p>Any thoughts...? Answers to similar questions involved running qmake, but as I said, this produces the same error in this case. Thanks!</p>

<pre><code>#include &lt;QObject&gt;

class Counter : public QObject
{
    Q_OBJECT

public:
    Counter() { m_value = 0; }

    int value() const { return m_value; }

public slots:
    void setValue(int value);

signals:
    void valueChanged(int newValue);

private:
    int m_value;
};

void Counter::setValue(int value)
{
    if (value != m_value) {
        m_value = value;
        emit valueChanged(value);
    }
}


int main()
{
    Counter a, b;
        QObject::connect(&amp;a, SIGNAL(valueChanged(int)),
                         &amp;b, SLOT(setValue(int)));

        a.setValue(12);     // a.value() == 12, b.value() == 12
        b.setValue(48);     // a.value() == 12, b.value() == 48
}
</code></pre>