Hello!

I want to watch the download progress of the html-content of the webpage. I use for it the QProgressBar.

But this function receives -1 for bytesTotal:
Qt Code:
  1. void Dialog::replyProgress(qint64 bytesReceived, qint64 bytesTotal)
  2. {
  3. ui->progressBar->setValue( bytesReceived );
  4. ui->progressBar->setMaximum( bytesTotal );
  5.  
  6. qDebug() << bytesReceived;
  7. qDebug() << bytesTotal;
  8. }
To copy to clipboard, switch view to plain text mode 

This is my module which gets content from the webpage:
Qt Code:
  1. #ifndef DOWNLOADER_H
  2. #define DOWNLOADER_H
  3.  
  4. #include <memory>
  5.  
  6. #include <QObject>
  7. #include <QString>
  8. #include <QNetworkReply>
  9. #include <QNetworkRequest>
  10. #include <QNetWorkAccessManager>
  11.  
  12. class Downloader : public QObject
  13. {
  14. Q_OBJECT
  15.  
  16. public:
  17.  
  18. void fetch( const QString &url )
  19. {
  20. m_reply.reset(m_manager->get( QNetworkRequest( QUrl( url ) ) ) );
  21. connect( m_reply.get( ), SIGNAL( finished( ) ),
  22. this, SLOT( replyFinished( ) ) );
  23. connect( m_reply.get( ), SIGNAL( downloadProgress( qint64, qint64 ) ),
  24. this, SLOT( slotDownloadProgress(qint64, qint64 ) ) );
  25. }
  26.  
  27. signals:
  28. void signalWithContent( QString * );
  29. void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
  30.  
  31. private slots:
  32. void replyFinished( )
  33. {
  34. QByteArray data = m_reply->readAll( );
  35. QString content( data );
  36. emit signalWithContent( &content );
  37. }
  38.  
  39. void slotDownloadProgress( qint64 bytesReceived, qint64 bytesTotal )
  40. {
  41. emit downloadProgress( bytesReceived, bytesTotal );
  42. }
  43.  
  44. private:
  45. std::shared_ptr<QNetworkAccessManager> m_manager =
  46. std::make_shared<QNetworkAccessManager>( this );
  47.  
  48. std::shared_ptr<QNetworkReply> m_reply;
  49. };
  50.  
  51. #endif // DOWNLOADER_H
To copy to clipboard, switch view to plain text mode