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

时间:2011-08-26 15:28:58

标签: qt qt4

这是我使用“CONNECT”的代码。我用它去插槽“slotReadyRead”,在那里我可以阅读回复的内容。 但是我在调​​试或运行程序时有一条消息,即---->

QObject :: connect:不兼容的发送方/接收方参数         QNetworkReplyImpl :: readyRead() - >主窗口:: 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);

2 个答案:

答案 0 :(得分:6)

插槽需要具有与信号兼容的签名。所以要么将其定义为:

void slotReadyRead();

或者将回复设为可选:

void slotReadyRead(QNetworkReply* reply = null);

答案 1 :(得分:3)

如果不是插件,则无法将插头强行插入插座。我看到两个选择:

  1. reply成为MainWindow的成员(快速而肮脏的解决方案)
  2. 创建一个新的类,其中有一个QNetworkReply*作为成员,一个插槽用于处理准备好的回复数据。
  3. 顺便说一句:我想你想要connect(reply, SIGNAL(finished()), this, SLOT(slotProcessReply())documentation)。 And here is the HTTP example from the Qt example collection!请查看network/http/httpwindow.hnetwork/http/httpwindow.cpp