1

我有一个问题.. 我正在向 php 脚本发出 post 请求。我正在以 xml 的形式返回结果。我怎样才能让我的 qprogressbar 工作。我试过这个:v

oid MainWindow::init()
{
    url = "http://127.0.0.1:8888/direkt_php_qt.php";
    manager = new QNetworkAccessManager(this);
    connect(manager, SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(updateDataTransferProgress(qint64,qint64)));
    connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
}

void MainWindow::updateDataTransferProgress(qint64 bytesReceived, qint64 bytesTotal)
{
    ui->progressBar->setMaximum(bytesTotal + (bytesTotal * 0.25));
    ui->progressBar->setValue(bytesReceived);
    ui->progressBar->show();
}

但它不起作用。我收到错误: Object::connect: No such signal QNetworkAccessManager::downloadProgress(qint64,qint64)

我怎样才能使它与 manager 变量或类似的东西一起工作。

编辑 2:这是例如调用 init() 的函数

void MainWindow::Citanje_korisnika()
{
    init();

    QUrl params;
        params.addQueryItem("action","Citanje_korisnika");

        QByteArray data;
        data.append(params.toString());
        data.remove(0,1);

        QNetworkRequest request;
        request.setUrl(url);
        request.setHeader(QNetworkRequest::ContentTypeHeader,
        QVariant("application/x-www-form-urlencoded"));

        reply = manager->post(request, data);

}

我尝试了您的代码,但总是意外退出程序。你能改变我调用 post 方法的函数吗,以便它可以与 init() 一起使用

4

1 回答 1

1

donwloadProgress 是QNetworkReply的信号。尝试这样的事情:

url = "http://127.0.0.1:8888/direkt_php_qt.php";
manager = new QNetworkAccessManager(this);

QNetworkReply* reply = manager->get(QNetworkRequest(url));
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),this, SLOT(updateDataTransferProgress(qint64,qint64)));
于 2012-02-01T12:03:14.023 回答