bts-007
1st June 2013, 10:35
I took an example program from Qt for qquickview. I am getting an error(undefined reference to 'vtable for ApplicationData', collect2 ld returned 1 exit status) when I add the class in main.cpp. Here is the code
#include<QQuickView>
#include<QGuiApplication>
#include<QObject>
#include<QQmlContext>
#include<QDateTime>
//#include"applicationdata.h"
class ApplicationData : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE QDateTime getCurrentDateTime() const {
return QDateTime::currentDateTime();
}
};
int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);
QQuickView view;
ApplicationData data;
view.rootContext()->setContextProperty("applicationData", &data);
view.setSource(QUrl::fromLocalFile("MyItem.qml"));
view.show();
return app.exec();
}
I took the class and placed in applicationdata.h. I didn't get error and the output was perfect. what is the reason I can't understand.
#include<QQuickView>
#include<QGuiApplication>
#include<QObject>
#include<QQmlContext>
#include<QDateTime>
//#include"applicationdata.h"
class ApplicationData : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE QDateTime getCurrentDateTime() const {
return QDateTime::currentDateTime();
}
};
int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);
QQuickView view;
ApplicationData data;
view.rootContext()->setContextProperty("applicationData", &data);
view.setSource(QUrl::fromLocalFile("MyItem.qml"));
view.show();
return app.exec();
}
I took the class and placed in applicationdata.h. I didn't get error and the output was perfect. what is the reason I can't understand.