QNetworkAccessManager in QThread



  • I am having a small problem on using QNetworkAccessManager in QThread. The error message is: "Object::connect: No such slot QThread::replyFinished(QNetworkrReply*)"

    And my code is header
    @
    class SSLReceive : public QThread
    {
    //Q_OBJECT

    public slots:
    void replyFinished(QNetworkReply* net_reply);

    protected:
    void run();

    private:
    void initialize();
    QNetworkAccessManager* manager;
    QSslConfiguration config;
    };
    @
    implement
    @
    void SSLReceive::replyFinished(QNetworkReply *net_reply)
    {
    QByteArray data = net_reply->readAll();
    QString str(data);

    //emit onFinished(net_reply);
    

    }

    void SSLReceive::run()
    {
    initialize();

    config.setPeerVerifyMode(QSslSocket::VerifyNone);
    QNetworkRequest request;
    string target = IM_url_getData;
    
    request.setUrl(QUrl(target.c_str()));
    request.setRawHeader("User-Agent", "DK");
    request.setRawHeader("Content-type", "text/plain");
    request.setSslConfiguration(config);
    connect(manager, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(replyFinished(QNetworkReply*))); //<-- error
    manager->get(request);
    

    }

    void SSLReceive::initialize()
    {
    manager = new QNetworkAccessManager;
    config = QSslConfiguration::defaultConfiguration();
    }
    @
    I definitly have 'replyFinished(QNetworkrReply*)' in my class which is derived by QThread. I dont know why this happens.. Should I put something else instead of 'this'?

    What am I missing? Please help!

    [Edit: added @ tags; mlong]



  • You need the Q_OBJECT macro in order to support slots.


  • Moderators

    Why are you putting the QNetworkAccessManager in its own thread? It is already asynchronous.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.