Hi Kamb!z,
Here is the working example I have complied and run it ……. !
// —— sample_ttr.pro —-
#————————————————————————-
#
Project created by QtCreator 2014-05-05T18:05:02
#
#————————————————————————-
QT += core gui
QT += quick
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = sample_ttr
TEMPLATE = app
SOURCES += main.cpp
HEADERS += \
ApplicationData.h
FORMS +=
OTHER_FILES += \
MyItem.qml
——————————————————————————————————————
// —— main.cpp —-
#include <QApplication>
#include <QtQuick/QQuickView>
#include <QQmlContext>
#include “ApplicationData.h”
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QQuickView view;
ApplicationData data;
view.rootContext()->setContextProperty(“ApplicationData”, &data);
view.setSource(QUrl::fromLocalFile(“MyItem.qml”));
view.show();
return a.exec();
}
———————————————————————————————————————
// —- ApplicationData.h —-
#ifndef APPLICATIONDATA_H
#define APPLICATIONDATA_H
#include <QObject>
#include <QDateTime>
class ApplicationData : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE QDateTime getCurrentDateTime() const {
return QDateTime::currentDateTime();
}
};
#endif // APPLICATIONDATA_H
——————————————————————————————————————-
// —— MyItem.qml —-
// MyItem.qml
import QtQuick 2.0
Text { text: applicationData.getCurrentDateTime() }
————————————————————————————————————————————
Thanks
Prashant
Hi , and Very very thank you Prashant!
↧