-1

I'm practicing with QT for one of my classes, and I keep getting Undefined reference to vtable for class despite no virtual function. I've looked around for a solution but it seems like they all had at least one function that is declared as virtual. Here is the code:

class C : public QObject
{
Q_OBJECT
public:
    C(int value) { value_ = 0; }
    int getValue() const { return value_; }
public slots:
    void setValue(int value){
        if (value != value_) {
            value_ = value;
            emit valueChanged(value);
        }
    }
signals:
    void valueChanged(int newValue){}
private:
    int value_;
};

I have no idea what's going on. I've tried changing the function names just in case they have the same name as some functions in the base class but it didn't solve anything. Here's the error:

/*path of file*/
error : undefined reference to `vtable for C'

Thanks

qwerty_99
  • 640
  • 5
  • 20
  • 1
    typo: change `void valueChanged(int newValue){}` to `void valueChanged(int newValue);`. The signals are not implemented, they are only defined. – eyllanesc Dec 17 '19 at 03:26
  • Thanks for the reply, and sorry for replying so late. I tried changing it but it still gives me ```LNK2001: unresolved external symbol "public: virtual void * __thiscall C``` – qwerty_99 Dec 18 '19 at 22:58
  • provide a [mre] – eyllanesc Dec 18 '19 at 22:59

1 Answers1

0

Like what eyllanesc said in comments, you should not provide a definition for signals. Signals should be only declared and the Qt meta-object compiler (moc) will generate required definitions for it. So:

...
signals:
    void valueChanged(int newValue);
...
Soheil Armin
  • 2,725
  • 1
  • 6
  • 18
  • Thanks, I didn't know that. However it's still giving me an ` LNK2001: unresolved external symbol "public: virtual void * __thiscall C ` error – qwerty_99 Dec 18 '19 at 23:02