Tielhalter

Untitled

Feb 16th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3.  
  4. Widget::Widget(QWidget *parent) :
  5.     QWidget(parent),
  6.     ui(new Ui::Widget)
  7. {
  8.     ui->setupUi(this);
  9.     apiUrl = "http://www.forismatic.com/api/1.0/";
  10.     requestString = "method=getQuote&format=text";
  11.     QNetworkRequest request(apiUrl);
  12.     reply = manager.post(request, requestString);
  13.     connect(reply, SIGNAL(finished()),this, SLOT(getReplyFinished()));
  14.     connect(reply, SIGNAL(readyRead()), this, SLOT(readyReadReply()));
  15. }
  16.  
  17. Widget::~Widget()
  18. {
  19.     delete ui;
  20. }
  21.  
  22. void Widget::readyReadReply()
  23. {
  24.     QString answer = QString::fromUtf8(reply->readAll());
  25.     ui->textEdit->setText(answer);
  26. }
  27.  
  28. void Widget::getReplyFinished()
  29. {
  30.     reply->deleteLater();
  31. }
  32.  
  33. void Widget::on_pushButton_clicked()
  34. {
  35.     QString answer = QString::fromUtf8(reply->readAll());
  36.     ui->textEdit->setText(answer);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment