Results 1 to 2 of 2

Thread: Download Progress of the html-content of the webpage

  1. #1
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Download Progress of the html-content of the webpage

    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 

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Download Progress of the html-content of the webpage

    Your question is answered in the documentation of the signal your slot is connected to.

Similar Threads

  1. not able to find the button in a html webpage
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 0
    Last Post: 25th June 2013, 07:54
  2. progress of download operation
    By sanjeet in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 11th November 2011, 06:52
  3. Detecting finished download of HTML content for QWebView
    By TropicalPenguin in forum Qt Programming
    Replies: 3
    Last Post: 21st June 2011, 19:44
  4. Replies: 0
    Last Post: 3rd December 2010, 15:10
  5. Replies: 3
    Last Post: 17th February 2010, 12:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.