Reputation: 5805
Hi all I have problem with qprogressbar. How can I make it smooth? I want it to go smoothly from 0 to 100% . I am using it with reply variable which reads data from php script and returning me data. I need to wait 3-4 seconds to get my data I want that progressbar to go smoothly from 0 to 100 and I only have instantly from 0-100.
Here is my code:
void MainWindow::updateDataTransferProgress(qint64 bytesReceived, qint64 bytesTotal)
{
ui->progressBar->setMaximum(bytesTotal);
ui->progressBar->setValue(bytesReceived);
}
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);
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),this, SLOT(updateDataTransferProgress(qint64,qint64)));
}
If you need more code..just tell me.
EDIT 2: Here is my another part of code:
void 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*)));
}
So program starts and first thing it goes into functionvoid MainWindow::Citanje_korisnika()
then it goes to void MainWindow::init()
and then void MainWindow::updateDataTransferProgress(qint64 bytesReceived, qint64 bytesTotal)
problem is. I want to make this progress bar to go smoothly from the begginig of the program until he downloaded all data to my reply variable.
Now I am getting my form shown and then I waint 3-4 sec nothing is happening, I see my progress bar at 0 and nothing is filled with data and then after some time progress bar jumpes to 100% and data is show.. So I want this perios while program is loading from server to see my progress bar going from 0-100 at some normal speed. Now I only see blank fileds and then boom everything is on. I want to make it all go smoothly. If you know what I mean.
Upvotes: 0
Views: 839
Reputation: 2004
Looks like here the bytesReceived == bytesTotal
and thats why its jumping from 0 to 100% immediately. If you know approximate size of bytesTotal
you can set QNetworkReply::setReadBufferSize(qint64 size)
to fraction of bytesTotal
. Than at least you will some progress. However as mentioned in the docu this will throttle down your download speed and I see no point in that.
Upvotes: 1