声明:因网易博客将关闭,移到此
1.这里主要是介绍,如何在c++中调用QML中的函数和设置QML中的属性的问题
2.具体代码
// UICtest.qml
import Qt 4.7
Rectangle {
id: mainWidget;
width: 640
height: 480
function callbyc(v)
{
mainWidget.color = v;
return "finish";
}
Rectangle{
id: secondRect;
x: 100;
y: 20;
width: 400;
height: 300;
Rectangle{
x: 10;
y: 20;
width: 30;
height: 40;
color: "#FF035721"
Text {
objectName: "NeedFindObj";
anchors.fill: parent;
text: "";
}
}
}
}
// main.cpp
#include <QtGui/QApplication>
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeComponent>
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeItem&g

本文档介绍了如何在C++代码中直接调用QML中的函数和设置QML组件的属性。主要通过QMetaObject的invokeMethod方法来实现对QML函数的调用,并展示了设置QML根节点属性的示例。
最低0.47元/天 解锁文章
623

被折叠的 条评论
为什么被折叠?



