如何解决(发送者/接收者参数不兼容)的问题?

发布于 2024-12-01 17:43:51 字数 953 浏览 0 评论 0原文

这是我使用 CONNECT 的代码。我用它来转到插槽 slotReadyRead ,我可以在其中读取回复内容。 但是我在调​​试或运行程序时收到一条消息

QObject::connect:发送者/接收者参数不兼容 QNetworkReplyImpl::readyRead() --> MainWindow::slotReadyRead(QNetworkReply*)

.cpp

    void MainWindow::on_pushButton_clicked()
{
     QNetworkAccessManager* manager = new QNetworkAccessManager(this);
     QNetworkRequest request;
     request.setUrl(QUrl("http://lascivio.co/mobile/get.php?name=marwa"));
     QNetworkReply *reply = manager->get(request);
     connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead(QNetworkReply*)));
}
void MainWindow::slotReadyRead(QNetworkReply* reply)
{
    QByteArray b (reply->readAll());
    QString s(b);
    ui->lineEdit->setText(s);
}

.h

public slots:
    void slotReadyRead(QNetworkReply* reply);

Here is the code where I use CONNECT.I use it to go to the slot slotReadyRead where i can read the content the reply.
But I have a message while debugging or running the program which is

QObject::connect: Incompatible sender/receiver arguments
QNetworkReplyImpl::readyRead() --> MainWindow::slotReadyRead(QNetworkReply*)

.cpp

    void MainWindow::on_pushButton_clicked()
{
     QNetworkAccessManager* manager = new QNetworkAccessManager(this);
     QNetworkRequest request;
     request.setUrl(QUrl("http://lascivio.co/mobile/get.php?name=marwa"));
     QNetworkReply *reply = manager->get(request);
     connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead(QNetworkReply*)));
}
void MainWindow::slotReadyRead(QNetworkReply* reply)
{
    QByteArray b (reply->readAll());
    QString s(b);
    ui->lineEdit->setText(s);
}

.h

public slots:
    void slotReadyRead(QNetworkReply* reply);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独守阴晴ぅ圆缺 2024-12-08 17:43:51

该插槽需要具有与信号兼容的签名。因此,要么将其定义为:

void slotReadyRead();

要么将回复设为可选:

void slotReadyRead(QNetworkReply* reply = null);

The slot needs to have a signature compatible with the signal. So either define it as:

void slotReadyRead();

Or make the reply optional:

void slotReadyRead(QNetworkReply* reply = null);
£冰雨忧蓝° 2024-12-08 17:43:51

如果无意的话,您不能强行将插头插入插座。我看到两个选项:

  1. 使 reply 成为 MainWindow 的成员(快速而肮脏的解决方案)
  2. 创建一个新类,该类将具有 QNetworkReply* 作为一个成员和一个槽,用于在准备就绪时处理回复的数据。

顺便说一句:我想你想要 connect(reply, SIGNAL(finished()), this, SLOT(slotProcessReply()) (文档)。这里是 Qt 示例集合中的 HTTP 示例! a href="http://doc.qt.nokia.com/4.7/network-http-httpwindow-h.html" rel="nofollow">network/http/httpwindow.h 和 network/http/httpwindow.cpp

You cannot force a plug into a socket, if it is not meant to be. I see two options:

  1. Make reply a member of MainWindow (the quick and dirty solution)
  2. Create a new class that will have a QNetworkReply* as a member and a slot to process the data of the reply, when it is ready.

BTW: I think you want to connect(reply, SIGNAL(finished()), this, SLOT(slotProcessReply()) (documentation). And here is the HTTP example from the Qt example collection! Have a look at network/http/httpwindow.h and network/http/httpwindow.cpp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文