PDA

View Full Version : Can't make Q_INVOKABLE macro use compile



frankiefrank
20th September 2011, 21: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?

wysota
20th September 2011, 21:42
What is the error you get? Did you remember to run qmake?

frankiefrank
20th September 2011, 21:49
This is happening in visual studio.

I get this warning in the output:
"MyQmlInterface.h(28): Warning: No relevant classes found. No output generated."
And then a bunch of compilation errors for different classes of mine.

wysota
20th September 2011, 22:41
The code looks correct. Could you prepare a minimal compilable (well, almost) example reproducing the problem?

stampede
20th September 2011, 22:44
I assume the closing bracket is not missing in your final code ? :)


/* THIS CODE WON't COMPILE
Q_INVOKABLE QDateTime getCurrentDateTime() const {
return QDateTime::currentDateTime();
} // <- this closing bracket */

frankiefrank
22nd September 2011, 14:35
Thank you stampede! Goddamit! :-)

And thanks wysota for your time as well!