Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1.  
  2. // =============================================================================
  3. // DownloadSparkData()
  4. // =============================================================================
  5. //
  6. void Vasama::DownloadSparkData()
  7. {
  8. SetStatusText( "Initialize download...");
  9. iDlManager = new QNetworkAccessManager( this );
  10. connect( iDlManager,
  11. SIGNAL( finished( QNetworkReply* )),
  12. this,
  13. SLOT( DataDownloadFinished( QNetworkReply* )));
  14.  
  15. iDlManager->get( QNetworkRequest( QUrl( iBaseUrl + KSparkTxd )));
  16. }
  17.  
  18. // =============================================================================
  19. // DataDownloadFinished()
  20. // =============================================================================
  21. //
  22. void Vasama::DataDownloadFinished( QNetworkReply* reply )
  23. {
  24. SetStatusText( "Download finished...");
  25.  
  26. QVariant statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
  27. qDebug() << "Vasama::DataDownloadFinished() status: " << statusCode;
  28.  
  29. if (reply->error() == QNetworkReply::NoError && statusCode.toInt() == 200 )
  30. {
  31. // Read bytesfrom the reply
  32. QByteArray bytes = reply->readAll(); // bytes
  33. QString string( bytes ); // string
  34. string.remove( QChar('\r')); // strip MS-DOS carriage returns
  35. ParseData( string );
  36. }
  37. else
  38. {
  39. if ( !statusCode.toInt() ) statusCode.setValue( -1 );
  40. SetStatusText( "Download failed! (Response code: " + statusCode.toString() + ")");
  41. }
  42.  
  43. reply->deleteLater();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement