开发者

QNetworkAccessManager finished signal is not emitted when compiled in release mode (VS 2005)

开发者 https://www.devze.com 2023-02-06 22:56 出处:网络
I have a class that reads web pages. It works as expected when it is built in the debug mode in Visual studio, but doesn\'t work when it is built in release mode.

I have a class that reads web pages. It works as expected when it is built in the debug mode in Visual studio, but doesn't work when it is built in release mode.

Basically, the QNetworkAccessManager's finished signal never gets emitted.

I have the code stripped to the bare working minimum and it still doesn't work. I have tried to use QtNetworkd4.lib in release mode (the same library as in debug mode) and disable optimization, but no effect.

Qt version 4.4

Edit

Here is some sample code.

Header:

#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QStringList>

class WebReader : public QObject{
    Q_OBJECT

public:
    QStringList *pageData_;
    WebReader();
    ~WebReader();
    void fetch(const QString &url);

public slots:
    void slotReplyFinished(QNetworkReply *reply);

protected:
    QNetworkAccessManager *netManager_;

private: 
    QNetworkReply *netReply_;
};

Cpp:

WebReader::WebReader(){
    netManager_ = new QNetworkAccessManager(this);
    pageData_ = NULL;
    connect(netManager_, SIGNAL(finished(QNetworkReply *)), 
                            this, SLOT(slotReplyFinished(QNetworkReply *)));
}
WebReader::~WebReader(){    
}

// Send a request to read a web page
void WebReader::fetch(const QString &url){
    netReply_ = netManager_->get(QNetworkRequest(QUrl(url)));
}

// SLOT that accepts the read data from the webpage
void WebReader::slotReplyFinished(QNetworkReply *reply){
    if (NULL != pageData_){
        d开发者_开发百科elete pageData_;
    }
    pageData_ = new QStringList(QString(reply->readAll()).split(QString("\n")));
    netReply_->deleteLater();
}

As you see, it is stripped down to a bare minimum that works in debug mode.


Copy libeay32 and ssleay32 to the same folder with your program.

0

精彩评论

暂无评论...
验证码 换一张
取 消