01-17-2013 09:24 AM
Hi all,
I'm trying to create a Custom Data model with some functions available through the QML code. Here is header file:
#ifndef XMLDATAMODEL_HPP
#define XMLDATAMODEL_HPP
#include <QObject>
#include <QString>
#include <QVariant>
#include <QMetaType>
#include <bb/cascades/QListDataModel>
#include <bb/data/XmlDataAccess>
#include <bb/cascades/GroupDataModel>
#include <bb/cascades/DataModel>
class XmlDataModel: public bb::cascades::DataModel{
public:
XmlDataModel();
virtual ~XmlDataModel();
// Required interface implementation
virtual int childCount(const QVariantList& indexPath);
virtual bool hasChildren(const QVariantList& indexPath);
virtual QVariant data(const QVariantList& indexPath);
public:
Q_INVOKABLE
void load(const QString& file_name);
Q_INVOKABLE
void setHeaderName(const QString& headerName);
private:
QVariant *m_sourceList;
QString *m_headerName;
};
#endif
And this is the QML implementation:
onCreationCompleted: {
console.log("main.qml loaded");
_model.setHeaderName("hello");
}But when the QML code try to execute the setheaderName function, I get htis error :
TypeError: Result of expression '_model.setHeaderName' [undefined] is not a function.
i the _model is accessible by the QML code, but I don't know why I can not execute my own functions... ![]()
Can anybody help me??
Solved! Go to Solution.
01-17-2013 09:57 AM
Make it a Q_OBJECT:
class XmlDataModel: public bb::cascades::DataModel{
Q_OBJECT
...01-17-2013 11:52 AM
If I do this, I get this error when compiling:
undefined reference to `vtable for XmlDataModel'
01-17-2013 11:59 AM
01-17-2013 12:04 PM
It works now.
Thanks!!