Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef BUSREADER_H
- #include <QObject>
- #ifdef QT_QML_DEBUG
- #include <QtQuick>
- #endif
- #include <QGuiApplication>
- #include <QQuickView>
- #include <QtQml>
- #define BUSREADER_H
- class BusReader: public QObject {
- Q_OBJECT
- public:
- Q_INVOKABLE bool postMessage(const QString &msg);
- Q_INVOKABLE QString getBus(const QString &msg);
- Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged)
- const QString html ( ) const;
- void setHtml(const QString &newHtml);
- public slots:
- void refresh();
- void handleNetworkData(QNetworkReply *networkReply);
- private:
- QNetworkAccessManager networkManager;
- QString s_html;
- signals:
- void htmlChanged();
- };
- #endif // BUSREADER_H
- #include "BusReader.h"
- bool BusReader::postMessage(const QString &msg) {
- qDebug() << "Called the C++ method with" << msg;
- return true;
- }
- QString BusReader::getBus(const QString &msg) {
- QNetworkRequest newRequest("http://url.com="+msg);
- networkManager.get(newRequest);
- connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
- this, SLOT(handleNetworkData(QNetworkReply*)));
- return msg;
- }
- void BusReader::handleNetworkData(QNetworkReply *networkReply)
- {
- QUrl url = networkReply->url();
- if (!networkReply->error()) {
- QString response(networkReply->readAll());
- qDebug() << response;
- }
- networkReply->deleteLater();
- }
- const QString BusReader :: html ( ) const {
- return s_html;
- }
- void BusReader::setHtml(const QString &newHtml)
- {
- s_html = newHtml;
- emit htmlChanged ();
- }
- void BusReader::refresh() {
- qDebug() << "Called the C++ slot";
- }
- import QtQuick 2.0
- import Sailfish.Silica 1.0
- import com.saildev.components 1.0
- Page {
- property string code_txt
- id: page
- BusReader {
- id: test_BusReader
- }
- SilicaListView {
- id: listView
- model: 20
- anchors.fill: parent
- header: PageHeader {
- title: qsTr("ST: "+code_txt+" - "+ test_BusReader.getBus(code_txt) +"!")
- }
- TextField {
- id: busTable
- focus: true
- text: test_BusReader.html
- }
- VerticalScrollDecorator {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement