????Qt Quick ?????????????漼???????????????????????????????豸????????????????????????ó???????????μ????????????? Qt Quick ??????洴?????????????????Qt Creator IDE?????????????????????? (QML) ?????????? Qt ??????? QtDeclarative ????鼴Qt Declarative UI????Щ??? Qt ??????????? C++ ??????????????????á?
?????о??????QML????????????????????QML??????C++ Application???????????????QT????????????????????????????:

???????QML????C++????
//main cpp
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
int main(int argc?? char *argv[])
{
QApplication app(argc?? argv);
QDeclarativeView view;
QDeclarativeContext *context = view.rootContext();
context->setContextProperty("backgroundColor"?? QColor(Qt::yellow));
view.setSource(QUrl::fromLocalFile("main.qml"));
view.show();
return app.exec();
}
//main.qml
import Qt 4.7
Rectangle {
width: 300
height: 300
color: backgroundColor
Text {
anchors.centerIn: parent
text: "Hello Yellow World!"
}
}
????????C++??????????
//main cpp
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
int main(int argc?? char *argv[])
{
QApplication app(argc?? argv);
QDeclarativeView view;
view.rootContext()->setContextProperty("palette"?? new CustomPalette);
view.setSource(QUrl::fromLocalFile("main.qml"));
view.show();
return app.exec();
}
//main.qml
import Qt 4.7
Rectangle {
width: 240
height: 320
color: palette.background //????C++????
Text {
anchors.centerIn: parent
color: palette.text
text: "Click me to change color!"
}
MouseArea {
anchors.fill: parent
onClicked: {
palette.text = "blue";
}
}
}