Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkAccessManager in QThread
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager in QThread

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DVN2
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      You need the Q_OBJECT macro in order to support slots.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

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

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved