如何解决(发送者/接收者参数不兼容)的问题?
这是我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该插槽需要具有与信号兼容的签名。因此,要么将其定义为:
要么将回复设为可选:
The slot needs to have a signature compatible with the signal. So either define it as:
Or make the reply optional:
如果无意的话,您不能强行将插头插入插座。我看到两个选项:
reply
成为MainWindow
的成员(快速而肮脏的解决方案)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.cppYou cannot force a plug into a socket, if it is not meant to be. I see two options:
reply
a member ofMainWindow
(the quick and dirty solution)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