我是黑莓10开发者。我使用momentics IDE开发blackberry 10 app
我的项目包含4个文件:
(x.h)
#ifndef X_H
#define X_H
#include "Y.h"
class X: public Y {
Q_OBJECT
public:
explicit X (QObject *parent = 0);
/*...*/
#endif
(y.h)
#ifndef Y_H
#define Y_H
#include <QObject>
#include <QtGui/QSortFilterProxyModel>
class Y : public QSortFilterProxyModel {
Q_OBJECT
public:
explicit Y (QObject *parent = 0);
/*...*/
#endif
(main.cpp中)
#include "x.h"
#include "xModel.h"
/*...*/
qmlRegisterType<X>("com.lib", 0, 1, "X");
qmlRegisterType<xModel>("com.lib", 0, 1, "xModel");
/*...*/
(main.qml)
import com.lib 0.1
import bb.cascades 1.0
Page {
/*...*/
attachedObjects: [
X { /* INFOS: The super type of the component
X is unknown, some of its properties
are not validated.*/
id: myclass
sourceModel: xModel
},
xModel {
id: xMyModel
}
]
/*...*/
}
但是,当我在Momentics IDE中构建项目时,我看到了错误,但如果我在QtCreator中构建此代码(导入QtQuick而不是bb.cascades),那么我没有看到这样的错误:
errors: (asset:///main.qml:112:12: Cannot assign to non-existent property "sourceModel")
bb::cascades::QmlDocument:createRootObject document is not loaded or has errors, can't create root
我该怎么办?
答案 0 :(得分:1)
您需要为希望自定义组件拥有的每个属性添加Q_PROPERTY宏,正如其他人已经评论过的那样,您应该提供更多代码来真正帮助您。
无论如何要添加sourceModel属性,您的头文件应该如下所示
#ifndef X_H
#define X_H
#include "Y.h"
class X: public Y {
Q_OBJECT
Q_PROPERTY(typeOfSourceModel sourceModelAccessor WRITE setSourceModel READ sourceModel NOTIFY sourceModelChanged)
public:
explicit X (QObject *parent = 0);
/*...*/
#endif
其中sourceModelAccessor是sourceModel属性的访问器,setSourceModel是mutator,sourceModelChanged是信号。