[SOLVED] Updater for my app



  • I would like to implement a function that checks if there is an updated version of my app, and I took "this":http://www.bogotobogo.com/Qt/Qt5_QNetworkRequest_Http_File_Download.php as an example. Now I would like to ask: to create a progress bar that shows the progress of the download, I need to know the final size of the file and the current one. How can I do this?



  • You need to work with following classes and signals.

    QNetworkAccessManager
    QNetworkRequest
    QNetworkReply

    Look at following Signals of QNetworkReply.

    1. downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
    2. finished()


  • Following your example, I made this attempt:

    @
    //.h file

    ...
    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
    ...
    @

    @
    //.cpp file (class constructor)

    QNetworkReply* reply = m_WebCtrl.get(QNetworkRequest(imageUrl));
    connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
    SLOT(downloadProgress(qint64,qint64)));
    @

    @
    //.cpp file (function declaration)

    void FileDownloader::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
    {
    qDebug() << bytesReceived << bytesTotal;
    }
    @

    But the IDE raises this error:

    QObject::connect: No such slot FileDownloader::downloadProgress(qint64,qint64)



  • Did you define following function as slot under public slots section ?

    @void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);@



  • Solved. Another question: If I wanted create a continually updated QLabels, which displays the bytes downloaded? A similar thing

    11 of 100 byets downloaded



  • You can do it. If it is single threaded application, you need to process the events using processEvents(..) method. If it multi threaded application, you can move the downloader code to worker thread and use the signal/slot mechanism to update from worker thread to main thread.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.