0

I have some signal in my class, is called requestFinished.
Also i have slot _finished, which should activate that signal.
But i have error undefined reference to MY_SIGNAL.
Here is _finished:

void VK::_finished(QNetworkReply *reply) {
    if (reply->error() != QNetworkReply::NoError) {
        qDebug() << (QString) reply->readAll();
    } else {
        QString json(reply->readAll());
        VKResponse *response = new VKResponse(json);
        VKError *error = new VKError(json);
        VKAnswer *answer = new VKAnswer(error, response);
        emit requestFinished(answer);
    }
}

Here is class VK:

class VK {
    public:
        VK(QString token);
        void request(QString method, std::map<QString, QString> data);
        ~VK();

    private:
        QString token;

    private slots:
        void _finished(QNetworkReply *reply);

    signals:
        void requestFinished(VKAnswer *answer);
};

As you can see, it contains method requestFinished in signals. What is my problem? Thanks.

Efog
  • 1,155
  • 1
  • 15
  • 33
  • 2
    Your problem is missing `Q_OBJECT` macro in `VK` class declaration. – vahancho Oct 31 '14 at 12:34
  • I removed it, because i get error `undefined reference to 'vtable for VK'` with it. Google said me it is problem with virtual methods, but i haven't them. //sorry for my english – Efog Oct 31 '14 at 12:36
  • 1
    `VK` must also be a subclass of `QObject` for singals/slots to work – king_nak Oct 31 '14 at 12:41

1 Answers1

3

Your VK class needs to publicly inherit QObject and include Q_OBJECT as the first thing:

class VK: public QObject {
    Q_OBJECT
    public:
        VK(QString token);
        void request(QString method, std::map<QString, QString> data);
        virtual ~VK();

    private:
        QString token;

    private slots:
        void _finished(QNetworkReply *reply);

    signals:
        void requestFinished(VKAnswer *answer);
};

you will then need to ensure the moc is run against that (usually this is automatic in QtCreator)

ratchet freak
  • 47,288
  • 5
  • 68
  • 106
  • Thanks for advice. I added `Q_OBJECT`, and inherited class from `QObject`. Now i have error `undefined reference to 'vtable for VK'`. //upd: solved. I added `virtual` to my destructor and now all working fine. Thanks! – Efog Oct 31 '14 at 12:42