Refresh battery data automatically

This commit is contained in:
Matti Viljanen 2019-01-05 21:57:35 +02:00
parent 790064e56b
commit 284d37755a
2 changed files with 8 additions and 1 deletions

View file

@ -4,6 +4,7 @@
#include <QObject>
#include <QString>
#include <QFile>
#include <QDebug>
class Battery : public QObject
{
@ -18,9 +19,10 @@ public:
int getCharge();
bool getCharging();
private:
public slots:
void updateData();
private:
QFile* chargeFile;
QFile* chargingFile;

View file

@ -8,6 +8,7 @@
#include <QQmlContext>
#include <QQuickView>
#include <QQmlEngine>
#include <QTimer>
#include "battery.h"
@ -27,6 +28,10 @@ int main(int argc, char *argv[])
QQuickView* view = SailfishApp::createView();
Battery battery;
QTimer updater;
QObject::connect(&updater, SIGNAL(timeout()), &battery, SLOT(updateData()));
updater.start(15000);
view->engine()->addImportPath("/usr/share/harbour-carbudget/qml");
view->rootContext()->setContextProperty("battery", &battery);
view->setSource(SailfishApp::pathTo("qml/harbour-batterybuddy.qml"));