Correct this code if im doing it wrong to calculate remainingTime of download a file
I tried to get remainingTime of downloading a file, as you can see from the source code below, i set some variables on updateFileStatus SLOT which i connected to updateProgress signal from QNetworkReply.
The problem is, the result fo the remainingTime is nor correct, it's return wrong time like 20:32:17 ... [QTime string format] // when i return the integer values of hour, minute, remSecond it's something like empty/null/uninitialized variable'
Code:
QString Status
::remainingTime() const {
if(_downloadRate){
qDebug() << _downloadRate << "###" << _totalLength << "###" << _completedLength;
int speed = _downloadRate;
int remLength = _totalLength - _completedLength;
int remSecond = remLength/speed;
int hour = remSecond/3600;
remSecond = remSecond%3600;
int minute = remSecond/60;
remSecond = remSecond%60;
return QTime(hour, minute, remSecond
).
toString();
}
}
QString Status
::downloadRate() const {
if(_downloadRate){
int rate = _downloadRate/1024;
if(rate < 1)
return QString(tr
("%1Kb/s").
arg(rate
));
else if(rate >= 1)
return QString(tr
("%1Mb/s").
arg(rate
));
}
}
void Status::updateFileStatus(qint64 bytesReceived, qint64 bytesTotal)
{
qDebug() << _startTime->elapsed();
if(!_totalLength)
_totalLength = bytesTotal;
_completedLength = bytesReceived;
_progress = _completedLength*100/_totalLength;
_downloadRate = _completedLength / _startTime->elapsed();
}
Re: Correct this code if im doing it wrong to calculate remainingTime of download a f
What does bytesTotal contain?
Re: Correct this code if im doing it wrong to calculate remainingTime of download a f
From the Qt doc :D
Quote:
bytesTotal indicates the total number of bytes expected to be downloaded
I told so, i connected to QNetworkReply::downloadProgress ( qint64 bytesReceived, qint64 bytesTotal ) [signal]
Re: Correct this code if im doing it wrong to calculate remainingTime of download a f
No, you don't understand. I'm asking about the exact value you get in this variable. Is it by any chance -1?
Re: Correct this code if im doing it wrong to calculate remainingTime of download a f
No, it's not.
It's exact file size!
To insure myself about that, also i put
Code:
qDebug() << _downloadRate << "###" << _totalLength << "###" << _completedLength;
to keep eye on it :|
Is it becuase of the type [qint64] which i get them from the downoadProgress ?
Re: Correct this code if im doing it wrong to calculate remainingTime of download a f
And how do you calculate the download rate?
Re: Correct this code if im doing it wrong to calculate remainingTime of download a f
Quote:
Originally Posted by
wysota
And how do you calculate the download rate?
Stop asking weird question, i provide the source, what is it?
Next i'm sure you gonna asking about my lip stick color :|
//
Anyway, i fixed it, i just mimic the minitube way to calculate downloadRate, remainingTime.
Re: Correct this code if im doing it wrong to calculate remainingTime of download a f
Quote:
Originally Posted by
Alir3z4
Stop asking weird question, i provide the source, what is it?
Quote:
Anyway, i fixed it, i just mimic the minitube way to calculate downloadRate, remainingTime.
So the question about how you calculate the rate wasn't so weird after all, was it?