qt进度条不能正常工作

时间:2012-02-01 11:47:08

标签: php c++ qt post qtnetwork

我有一个问题.. 我正在向php脚本发帖请求。我将结果作为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()

1 个答案:

答案 0 :(得分: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)));