当前位置:软件学习 > 其它软件 >>

QML一点点注意的地方

1、id需要小写
2、模块名首字母要大写
3、由原来的import Qt 4.7 修改为了import QtQuick 1.0
4、states是:[]
5、国际化用:qsTr()
6、导入js文件用:import *.js as Name
7、属性的设置声明方法:property int len 12,别名:property alias cellColor: rectangle.color/
      cpp中是:Q_PROPERTY(int hour READ hour WRITE setHour NOTIFY timeChanged)
8、信号声明:signal clicked(color cellColor),处理为onClincked
9、C++扩展组件继承:QObject
      注册组件 :qmlRegisterType<ClassName>(uri, 1, 0, "Class");  这样需要qml导入声明,也可以下面这样,qml可以直接使用

MyClass myObj; 
 
QDeclarativeEngine *engine=viewer.engine(); 
 
QDeclarativeContext *context=engine->rootContext(); 
 
context->setContextProperty("myObjectExposeByCXProperty", &myObj); 
      声明接口 :Q_INTERFACES(PluginInterface)
      导出接口:Q_EXPORT_PLUGIN2(exampleplugins, YourPlugin)
10、cpp函数被QML直接调用的方法:Q_INVOKABLE和public slots
11、cpp获取qml的函数

QDeclarativeComponent component(&engine, "MyItem.qml"); 
QObject *object = component.create(); 
QMetaObject::invokeMethod(object, "myQmlFunction",Q_RETURN_ARG(QVariant, returnedValue),Q_ARG(QVariant, arg)); 

摘自 缘起
补充:软件开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,