M
M
mefest2016-08-29 14:44:35
Qt
mefest, 2016-08-29 14:44:35

Why is the signal not connected to the slot?

There is a method:

QNetworkReply* QVkApi::request(QString method, QVariantMap args)
{
    QString req ="https://api.vk.com/method/";
    req+=method+"?";
    for(auto arg = args.begin(); arg != args.end();arg++){
        req += "&"+arg.key()+"="+arg.value().toString();
    }
    req += "&access_token=" + token + "&v=5.53";
    QNetworkRequest reques(req);
    QNetworkReply* reply = _accessManager->get(reques);
    connect(reply, &QNetworkReply::finished,this, &QVkApi::onReply);
    return reply;
}

Further in the User class, it is called and connected to the slot
User::User(int id, QObject *parent) : AbstractEntity(id,parent)
{
    QVariantMap args;
    args["fields"] = "photo_50,city,verified";
    args["name_case"] = "Nom";
    reply = api->request("users.get", args);
    connect(reply, &QNetworkReply::finished, this, &User::onUpdate);
}

But in the User class, the slot associated with it is not called (if you read QNetworkReaply after binding, it is empty), although in the QVkApi class everything connects and works fine.
class headers:
user.h
#ifndef USER_H
#define USER_H

#include "abstractentity.h"

class User : public AbstractEntity
{
    Q_OBJECT

public:
    explicit User(int id, QObject *parent = 0);

signals:

public slots:
    void onUpdate();

};

#endif // USER_H

abstractentity.h
#ifndef ABSTRACTENTITY_H
#define ABSTRACTENTITY_H

#include <QObject>
#include <QNetworkReply>

#include "qvkapi.h"

class AbstractEntity : public QObject
{
public:
    explicit AbstractEntity(int id, QObject *parent = 0);

    int id;

    QNetworkReply* reply;
protected:
    QVkApi* api;

};

#endif // ABSTRACTENTITY_H

Why is the signal not associated with the slot in the User class?
I ask you to help me solve the problem or please explain where I am stupid.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Martyanov, 2016-08-29
@mefest

And what is written to the console when connect?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question