我正在尝试使用QNetworkReply做一个简单的GET请求,但是完成()永远不会被调用,这是我的代码
QtTest::QtTest(QWidget *parent):QWidget(parent){
ui.setupUi(this);
auto network_access_manager = new QNetworkAccessManager(this);
auto reply = network_access_manager->get(QNetworkRequest(QUrl("http://www.whatsmyip.org/")));
connect(reply, SIGNAL(finished()), this, SLOT(download_finished()));
qDebug() << "Started";
}
void QtTest::download_finished() {
qDebug() << "Finished";
}
如果我在启动时检查输出,我会
QObject::connect: Cannot connect (null)::aboutToQuit() to QNativeWifiEngine::closeHandle()
Exception thrown at 0x749040F8 (KernelBase.dll) in QtTest.exe: 0x000006A6: The binding handle is invalid.
答案 0 :(得分:0)
验证您是否将download_finished()声明为插槽。
class QtTest : public QObject
{
Q_OBJECT
public:
QtTest(QObject *parent = 0);
private slots:
void download_finished();
};
答案 1 :(得分:-1)
更改download_finished的定义以包含回复;
信号是;完成(QNetworkReply *回复)所以
QtTest::download_finished(QNetworkReply *reply)
{
.... etc
确保在connect语句中包含该参数。