3

I'm developping an application for Blackberry 10 and I'm using the Momentics IDE (BB native SDK).

I get the following error when I try to execute the code below. Any one have an idea how can I fix this ?

Error

QMetaProperty::read: Unable to handle unregistered datatype 'DataHandler*' for property 'xxx::dataHandler'
asset:///main.qml:104: TypeError: Result of expression 'xxx.dataHandler' [undefined] is not an object.
Process 627863799 (xxx) terminated SIGSEGV code=1 fltno=11 ip=08055b30(/accounts/1000/appdata/com.ddd.xxx.testDev_e_xxx45b0f435/app/native/xxx@main+0x5d63) ref=006e0075

** xxx.hpp **

class xxx: public QObject {
Q_OBJECT

Q_PROPERTY(DataHandler* dataHandler READ getDataHandler)

public:
    xxx(bb::cascades::Application *app);
    virtual ~xxx() {
    }

    Q_INVOKABLE
    DataHandler* getDataHandler() const;

private:
    DataHandler* m_dataHandler;
}

** xxx.cpp **

xxx::xxx(bb::cascades::Application *app) :
        QObject(app) {
m_dataHandler = new DataHandler();
}

** QML file **

Button {
         id: backBtn
         objectName: "backBtnObject"
         text: qsTr("Back") + Retranslate.onLocaleOrLanguageChanged
         preferredWidth: backBtn.text.length
         visible: false
         onClicked: {
              xxx.dataHandler.displayLicencesList();
         }
 }
Mohamed Jihed Jaouadi
  • 1,427
  • 4
  • 25
  • 44

2 Answers2

5

You need to register your pointer type like this

qRegisterMetaType<ClassA*>("ClassA*");

(source)

Aralox
  • 1,441
  • 1
  • 24
  • 44
2

DataHandler is unknown type.

Q_PROPERTY docu says:

The type can be any type supported by QVariant

I'd try to encapsulate your DataHandler* in QVariant and make the property of type QVariant.

You could create the value containing your DataHandler pointer e.g like this:

const int DATA_HANDLER = QVariant::UserType +1;
//...
QVariant dataHandler( DATA_HANDLER, myDataHandlerPointer );
Valentin H
  • 7,240
  • 12
  • 61
  • 111
  • 1
    Thx !! **DataHandler** is QObject class that I created for loading data stuffs. I don't know why it doesn't work? If you check this [link](http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-exposecppattributes.html), you will see that's possible to call pointer in the Q_Property. – Mohamed Jihed Jaouadi Dec 02 '13 at 14:14
  • 1
    @user2072762: OK, interesting. This docu [link](http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-definetypes.html#registering-c-types-with-the-qml-type-system) says, QObject-derived classes may be used as types if they were registered. Have you seen the chapter **Registering C++ types with the QML type system**? Maybe qmlRegisterType() could help? – Valentin H Dec 02 '13 at 14:22