Qt World Summit: Submit your Presentation

Calculate Traffic through QNetworkAccessManager

  • Hi everyone,

    I would like to calculate the traffic (bytes received and sent) in my application (using a QWebView and also a download manager for file content).

    I would like the most generic solution (lowest level, that's why I think QNetworkAccessManager is the best way to do it if I configure the network request to always use the same manager).

    I explored the following:

    connect(networkManager(), &QNetworkAccessManager::finished, this, &WebWidget::replyFinished);

    but reply->bytesAvailable() is usually 0 because the bytes was already consume by the QWebView I assumed.

    I try to use QWebPage::totalBytes() but it's only when the page is loaded, watching a video in youtube doesn't update this value when the page is finished loaded.

    QNetworkRequest request(url);
    currentReply = networkManager()->get(request);
    connect(currentReply, &QNetworkReply::readyRead, this, &WebWidget::replyReadyRead);

    it works to get the number of bytes for a request, but doesn't really work in coordination to QWebView, I don't want to use QNerworkAccessManager::get() but of course QWebView::load().

    void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);

    I also assumed this function from QNetworkReply would be interresting.

    Thanks for your help/suggestions.

Log in to reply