Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

[Solved] Using a timer in qml, the signal of downloading a file is emitted multiple times...

$
0
0
Hi everyone, I have created a FileDownloader class, as those that exist on the web already: Here are some lines from the *.cpp file: void FileDownloader::downloadFile( QUrl url ) {     connect( &m_WebCtrl, SIGNAL(finished(QNetworkReply*)), SLOT(fileDownloaded(QNetworkReply*)) );       QNetworkRequest request( url );     m_WebCtrl.get( request ); }   QByteArray FileDownloader::downloadedData() const {     return m_DownloadedData; }   void FileDownloader::fileDownloaded(QNetworkReply *pReply) {     m_DownloadedData = pReply->readAll();       pReply->deleteLater();     // emit a signal     qDebug() << "emit downloaded";     emit downloaded(); } Then I created a Timer and a FileDownloader object in qml: FileDownloader {     id: fileToDownload     fileUrl: "http://www.example.com/file.txt"       onDownloaded: {         console.debug("onDownloaded...");     } }   Timer {     id: timer     interval: 3000     repeat: true     running: true       onTriggered: {         console.debug( "-----> tick", Date().toString() );         fileToDownload.downloadFile( fileToDownload.fileUrl );     } } However I have the following problem: The first time that the timer is triggered the code works ok, but the second, third, etc time the signal is emitted multiple times. Each time once more than the previous. Here is the text from the log window: qml: -----> tick 17:31:38 downloadFile emit downloaded qml: onDownloaded... qml: -----> tick 17:31:41 downloadFile emit downloaded qml: onDownloaded... emit downloaded qml: onDownloaded... qml: -----> tick 17:31:44 downloadFile emit downloaded qml: onDownloaded... emit downloaded qml: onDownloaded... emit downloaded qml: onDownloaded... qml: -----> tick 17:31:47 downloadFile emit downloaded qml: onDownloaded... emit downloaded qml: onDownloaded... emit downloaded qml: onDownloaded... emit downloaded qml: onDownloaded... any help, idea? Thanx in advance!

Viewing all articles
Browse latest Browse all 4972

Trending Articles