frankiefrank
20th September 2011, 20:40
I'm trying to create an object for use for QML integration.
If I uncomment the marked code, I get compilation errors:
// header
#ifndef MY_QML_INTERFACE_H
#define MY_QML_INTERFACE_H
#include <QObject>
#include <QDateTime>
class MyQmlInterface : public QObject
{
Q_OBJECT
public:
Q_PROPERTY(QString singleValue READ singleValue WRITE setSingleValue NOTIFY singleValueChanged);
const QString &singleValue() const;
void setSingleValue(const QString &newSingleValue);
/* THIS CODE WON't COMPILE
Q_INVOKABLE QDateTime getCurrentDateTime() const {
return QDateTime::currentDateTime();
*/
signals:
void singleValueChanged();
private:
QString mSingleValue;
};
#endif
// Cpp
#include "MyQmlInterface.h"
const QString &MyQmlInterface::singleValue() const
{
return mSingleValue;
}
void MyQmlInterface::setSingleValue(const QString &newSingleValue)
{
if (newSingleValue == mSingleValue)
return;
mSingleValue = newSingleValue;
emit singleValueChanged();
}
Any idea why this doesn't work?
If I uncomment the marked code, I get compilation errors:
// header
#ifndef MY_QML_INTERFACE_H
#define MY_QML_INTERFACE_H
#include <QObject>
#include <QDateTime>
class MyQmlInterface : public QObject
{
Q_OBJECT
public:
Q_PROPERTY(QString singleValue READ singleValue WRITE setSingleValue NOTIFY singleValueChanged);
const QString &singleValue() const;
void setSingleValue(const QString &newSingleValue);
/* THIS CODE WON't COMPILE
Q_INVOKABLE QDateTime getCurrentDateTime() const {
return QDateTime::currentDateTime();
*/
signals:
void singleValueChanged();
private:
QString mSingleValue;
};
#endif
// Cpp
#include "MyQmlInterface.h"
const QString &MyQmlInterface::singleValue() const
{
return mSingleValue;
}
void MyQmlInterface::setSingleValue(const QString &newSingleValue)
{
if (newSingleValue == mSingleValue)
return;
mSingleValue = newSingleValue;
emit singleValueChanged();
}
Any idea why this doesn't work?