[ create a new paste ] login | about

Link: http://codepad.org/XrMWZNB0    [ raw code | fork ]

C++, pasted on Jun 16:
#include <QtGui/QApplication>
#include <QtCore/QDateTime>
#include <QtCore/QTimer>
#include <QDeclarativeContext>
#include "qmlapplicationviewer.h"

class ApplicationData : public QObject
 {
     Q_OBJECT
 public:

    ApplicationData()
    {
        m_timer = new QTimer(this);
        connect(m_timer, SIGNAL(timeout()), this, SLOT(updateTime()));
        m_timer->start(3000);
    }

     Q_INVOKABLE QDateTime getCurrentDateTime() const {
         return m_datetime;
     }

signals:
    void timeChanged(QDateTime);

private slots:
    void updateTime() {
        m_datetime = QDateTime::currentDateTime();
        emit timeChanged(m_datetime);
    }

private:
    QTimer *m_timer;
    QDateTime m_datetime;

 };


Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));

    ApplicationData *data = new ApplicationData();

    QmlApplicationViewer viewer;
    viewer.rootContext()->setContextProperty("applicationData", data);

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qml/testQml/main.qml"));
    viewer.showExpanded();

    return app->exec();
}


Create a new paste based on this one


Comments: