I'm trying to create an object for use for QML integration.

If I uncomment the marked code, I get compilation errors:
Qt Code:
  1. // header
  2. #ifndef MY_QML_INTERFACE_H
  3. #define MY_QML_INTERFACE_H
  4.  
  5. #include <QObject>
  6. #include <QDateTime>
  7.  
  8. class MyQmlInterface : public QObject
  9. {
  10. Q_OBJECT
  11.  
  12. public:
  13.  
  14. Q_PROPERTY(QString singleValue READ singleValue WRITE setSingleValue NOTIFY singleValueChanged);
  15.  
  16. const QString &singleValue() const;
  17. void setSingleValue(const QString &newSingleValue);
  18.  
  19. /* THIS CODE WON't COMPILE
  20. Q_INVOKABLE QDateTime getCurrentDateTime() const {
  21.   return QDateTime::currentDateTime();
  22. */
  23.  
  24. signals:
  25. void singleValueChanged();
  26. private:
  27. QString mSingleValue;
  28. };
  29.  
  30. #endif
  31.  
  32. // Cpp
  33. #include "MyQmlInterface.h"
  34.  
  35. const QString &MyQmlInterface::singleValue() const
  36. {
  37. return mSingleValue;
  38. }
  39.  
  40. void MyQmlInterface::setSingleValue(const QString &newSingleValue)
  41. {
  42. if (newSingleValue == mSingleValue)
  43. return;
  44. mSingleValue = newSingleValue;
  45. emit singleValueChanged();
  46. }
To copy to clipboard, switch view to plain text mode 

Any idea why this doesn't work?