rt,按照网上的例子写的如下:
main()函数:
#include <QtGui/QApplication>
#include "widget.h"
#include "QtDeclarative/QDeclarativeView.h"
#include "QDeclarativeContext"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDeclarativeView view;
QDeclarativeContext * context = view.rootContext();
context->setContextProperty("backgroundColor",QColor(Qt::yellow));
view.setSource(QUrl::fromLocalFile("tab.qml"));
view.show();
return a.exec();
}
tab.qml:
import Qt 4.7
Rectangle {
width: 300
height: 300
color: backgroundColor
Text {
anchors.centerIn: parent
text: "Hello Yellow World!"
}
}
感谢ing~~~~~~