将函数连接到 QHttp::requestFinished

问题描述 投票:0回答:1

我使用的是 Qt 4.1,这是编译到 Windows 98 的最后一个版本(尽管我在 Windows XP 上运行它,因为我有一个无法虚拟化 win98 的 AMD 处理器)。我无法访问 QNetworkManager 等更现代的类。

我正在尝试创建一种获取网址内容的方法。该类定义如下:

#ifndef __SONG_HPP
#define __SONG_HPP
#include <string>
#include <QWidget>

class Status : public QObject
{
    Q_OBJECT

signals:

public slots:
    void onRequestFinished(int id, bool error);

public:
    Status();
    virtual ~Status(){};
};
#endif

相关函数为:

Status::Status()
{
    QHttp *http = new QHttp("plaza.one");

    QHttpRequestHeader header("GET", "/status");
    header.setValue("Host", "plaza.one");
    http->request(header);

    bool what = QObject::connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(onRequestFinished(int, bool)));

    std::cout << what << std::endl;
}

void Status::onRequestFinished(int id, bool error)
{
    std::cout << "called" << std::endl;
}

QObject::connect 返回 true,但该函数永远不会被调用。

c++ qt qt4 retro-computing
1个回答
0
投票

我的代码(意识到我在某个时候不假思索地将其更改为

requestStarted
,而它应该是
requestFinished
)工作正常。

在 IE6 中打开 plaza.one 会发现,实际上从未建立过连接。它只是一直挂着。

© www.soinside.com 2019 - 2024. All rights reserved.