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

Qt Code:
  1. #include<QQuickView>
  2. #include<QGuiApplication>
  3. #include<QObject>
  4. #include<QQmlContext>
  5. #include<QDateTime>
  6. //#include"applicationdata.h"
  7.  
  8. class ApplicationData : public QObject
  9. {
  10. Q_OBJECT
  11. public:
  12. Q_INVOKABLE QDateTime getCurrentDateTime() const {
  13. return QDateTime::currentDateTime();
  14. }
  15. };
  16.  
  17.  
  18. int main(int argc, char *argv[]) {
  19. QGuiApplication app(argc, argv);
  20.  
  21. QQuickView view;
  22.  
  23. ApplicationData data;
  24. view.rootContext()->setContextProperty("applicationData", &data);
  25.  
  26. view.setSource(QUrl::fromLocalFile("MyItem.qml"));
  27. view.show();
  28.  
  29. return app.exec();
  30. }
To copy to clipboard, switch view to plain text mode 

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.