为信号增加价值

Add value to signal

这是任务:我捕获来自

的信号
QNetworkAccessManager* manager= new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(parse_data_request(QNetworkReply*)));
connect(manager, &QNetworkAccessManager::finished, manager,
&QNetworkAccessManager::deleteLater,Qt::QueuedConnection);

我想像这样使用 QNetworkReply* 发送到插槽 parse_data_request int 变量:

QNetworkAccessManager* manager= new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*,int)), this, SLOT(parse_data_request(QNetworkReply*,int)));
connect(manager, &QNetworkAccessManager::finished, manager,
&QNetworkAccessManager::deleteLater,Qt::QueuedConnection);

我该怎么做?

如果您正在使用 Qt5(您看起来是),那么您可以使用 lambda 作为连接目标...

int request_id = ...;
QNetworkAccessManager* manager= new QNetworkAccessManager(this);
connect(manager, &QNetworkAccessManager::finished, this,
        [this, request_id](QNetworkReply *reply)
        {
            parse_data_request(reply, request_id);
        });
connect(manager, &QNetworkAccessManager::finished, manager, &QNetworkAccessManager::deleteLater,Qt::QueuedConnection);