QObject连接函数

QObject connection function(QObject连接函数)
本文介绍了QObject连接函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我检查了其他类似的问题并尝试了他们的解决方案,但它们对我不起作用.

I checked other similar questions and tried their solutions but they don't work for me.

我基本上是在尝试制作一个仅发出发布请求的 http 客户端.为了做到这一点,我需要将 QNetworkManager 的完成信号连接到某个回调槽.

I'm basically trying to make a http client that only makes post requests. In order to do this, I need to connect QNetworkManager's finished signal to some callback slot.

这是我的代码.

h 文件:

...
public slots:
   void finishedSlot(QNetworkReply* reply);
private:
    QNetworkAccessManager *network_manager;
...

cpp 文件:

...
Class1::Class1(){
    network_manager = new QNetworkAccessManager(this);
    QObject::connect(network_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedSlot(QNetworkReply *)));
}
...
void Class1::finishedSlot(QNetworkReply* reply)
{
    // some logic with reply
}
...

如您所见,该插槽肯定存在,并且它是在头文件中的公共插槽下声明的.所以我不知道为什么会这样.我已经尝试过清理、运行 qmake 和重建.

As you can see, the slot is definitely present and it is declared under public slots in header file. So I have no idea why this is happening. I already tried clean, run qmake, and rebuild.

错误信息是:

"QObject::connect: No such slot QObject::finishedSlot(QNetworkReply*)"

"QObject::connect: No such slot QObject::finishedSlot(QNetworkReply *)"

有什么想法吗?

推荐答案

您可能忘记使用 Q_OBJECT 宏.每个实现自己的插槽/信号的类都需要该宏.不要忘记您需要将头文件/源文件添加到 .pro 文件中.

You probably forgot to use the Q_OBJECT macro. Every class that implements its own slots/signals needs that macro. Don't forget that you need to add your header/source file to the .pro file.

这篇关于QObject连接函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Bring window to front -gt; raise(),show(),activateWindow() don’t work(把窗户放在前面 -raise(),show(),activateWindow() 不起作用)
How to get a list video capture devices NAMES (web cameras) using Qt (crossplatform)? (C++)(如何使用 Qt(跨平台)获取列表视频捕获设备名称(网络摄像机)?(C++))
How to compile Qt as static(如何将 Qt 编译为静态)
C++ over Qt : Controlling transparency of Labels and Buttons(C++ over Qt:控制标签和按钮的透明度)
How to know when a new USB storage device is connected in Qt?(Qt如何知道新的USB存储设备何时连接?)
What is an event loop in Qt?(Qt 中的事件循环是什么?)