Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 KB | None | 0 0
  1. #ifndef BUSREADER_H
  2. #include <QObject>
  3.  
  4. #ifdef QT_QML_DEBUG
  5. #include <QtQuick>
  6. #endif
  7.  
  8. #include <QGuiApplication>
  9. #include <QQuickView>
  10. #include <QtQml>
  11. #define BUSREADER_H
  12.  
  13. class BusReader: public QObject {
  14.     Q_OBJECT
  15. public:
  16.     Q_INVOKABLE bool postMessage(const QString &msg);
  17.     Q_INVOKABLE QString getBus(const QString &msg);
  18.     Q_PROPERTY(QString html   READ html   WRITE setHtml   NOTIFY htmlChanged)
  19.     const QString html ( ) const;
  20.     void setHtml(const QString &newHtml);
  21.  
  22.  
  23.  
  24. public slots:
  25.     void refresh();
  26.     void handleNetworkData(QNetworkReply *networkReply);
  27.  
  28. private:
  29.     QNetworkAccessManager networkManager;
  30.     QString s_html;
  31.  
  32. signals:
  33.     void htmlChanged();
  34.  
  35. };
  36. #endif // BUSREADER_H
  37.  
  38.  
  39.  
  40.  
  41. #include "BusReader.h"
  42.  
  43.  bool BusReader::postMessage(const QString &msg) {
  44.     qDebug() << "Called the C++ method with" << msg;
  45.     return true;
  46. }
  47.  
  48.  QString BusReader::getBus(const QString &msg) {
  49.  
  50.      QNetworkRequest newRequest("http://url.com="+msg);
  51.      networkManager.get(newRequest);
  52.      connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
  53.                  this, SLOT(handleNetworkData(QNetworkReply*)));
  54.     return msg;
  55.  }
  56.  
  57.  
  58.  void BusReader::handleNetworkData(QNetworkReply *networkReply)
  59.  {
  60.      QUrl url = networkReply->url();
  61.      if (!networkReply->error()) {
  62.  
  63.          QString response(networkReply->readAll());
  64.          qDebug() << response;
  65.  
  66.      }
  67.  
  68.      networkReply->deleteLater();
  69.  }
  70.  
  71.  
  72.  const QString BusReader :: html ( ) const {
  73.      return s_html;
  74.  }
  75.  
  76. void BusReader::setHtml(const QString &newHtml)
  77. {
  78.      s_html = newHtml;
  79.      emit htmlChanged ();
  80. }
  81.  
  82. void BusReader::refresh() {
  83.     qDebug() << "Called the C++ slot";
  84. }
  85.  
  86. import QtQuick 2.0
  87. import Sailfish.Silica 1.0
  88. import com.saildev.components 1.0
  89.  
  90. Page {
  91.     property string code_txt
  92.  
  93.  
  94.     id: page
  95.  
  96.  
  97.     BusReader {
  98.         id: test_BusReader
  99.  
  100.  
  101.     }
  102.  
  103.  
  104.     SilicaListView {
  105.         id: listView
  106.         model: 20
  107.         anchors.fill: parent
  108.         header: PageHeader {
  109.             title: qsTr("ST: "+code_txt+" -  "+ test_BusReader.getBus(code_txt) +"!")
  110.         }
  111.  
  112.         TextField {
  113.             id:     busTable
  114.             focus: true
  115.             text: test_BusReader.html
  116.         }
  117.  
  118.  
  119.         VerticalScrollDecorator {}
  120.     }
  121.  
  122.  
  123.  
  124.  
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement