Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
joanpuigsanz
Posts: 27
Registered: ‎07-30-2011
My Device: Z10
My Carrier: Tmobile
Accepted Solution

Custom DataModel with custom callabe functions

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... :smileysad:

 

Can anybody help me??

Please use plain text.
New Contributor
ajalkane
Posts: 4
Registered: ‎01-17-2013
My Device: Dev Alpha B
My Carrier: RIM

Re: Custom DataModel with custom callabe functions

Make it a Q_OBJECT:

 

class XmlDataModel: public bb::cascades::DataModel{
Q_OBJECT
...
 
Please use plain text.
Contributor
joanpuigsanz
Posts: 27
Registered: ‎07-30-2011
My Device: Z10
My Carrier: Tmobile

Re: Custom DataModel with custom callabe functions

If I do this, I get this error when compiling:

 

 undefined reference to `vtable for XmlDataModel'

 

Please use plain text.
New Developer
andydragon
Posts: 11
Registered: ‎01-17-2013
My Device: BlackBerry Z10
My Carrier: Bell

Re: Custom DataModel with custom callabe functions

I had this, try clean and build manually.
Andrew Forget
BlackBerry Z10
Please use plain text.
Contributor
joanpuigsanz
Posts: 27
Registered: ‎07-30-2011
My Device: Z10
My Carrier: Tmobile

Re: Custom DataModel with custom callabe functions

It works now.

Thanks!!

Please use plain text.