Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. void MainWindow::Pobierz()
  2. { manager = new QNetworkAccessManager(this);
  3.  
  4. connect(manager, SIGNAL(finished(QNetworkReply*)),
  5. this, SLOT(replyFinished(QNetworkReply*)));
  6. //manager->get(QNetworkRequest(QUrl("http://www.nbp.pl/kursy/xml/LastA.xml")));
  7. manager->get(QNetworkRequest(QUrl("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml")));
  8.  
  9.  
  10. }
  11.  
  12. void MainWindow::replyFinished (QNetworkReply *reply)
  13. {
  14. if (reply->error() == QNetworkReply::NoError)
  15. {
  16.  
  17. QString filename = "walutkiy.xml";
  18. QFile file(filename);
  19. // Trying to open in WriteOnly and Text mode
  20. if(!file.open(QFile::WriteOnly |
  21. QFile::Text))
  22. {
  23. qDebug() << " Could not open file for writing";
  24. return;
  25. }
  26. // To write text, we use operator<<(),
  27. // which is overloaded to take
  28. // a QTextStream on the left
  29. // and data types (including QString) on the right
  30. QTextStream out(&file);
  31. out<<reply->readAll();
  32. file.flush();
  33. file.close();
  34. // file.open(QIODevice::ReadOnly);
  35. // doc.setContent(&file);
  36. // file.close();
  37.  
  38. }
  39. else
  40. {
  41.  
  42. ui->komunikat_2->setText("nie dziala error przy pobieraniu");
  43. }
  44.  
  45. reply->deleteLater();
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement