在我的上一篇博客中:Qt Quick起步
我介绍了如何使用Qt Creator创建一个Qt Quick项目, 这是一个基础项目。不过大多数时候,我希望用qml 设计的Qt UI和C++代码保持分离。UI设计者编辑qml文件,C++代码运行时加载它们,然后绑定事件并处理之,就像HTML一样。
这篇文章,我将描述如何做。
首先,设计一个qml文件表示一个简单的tab view窗口。
在main.qml文件中,添加下面的qml语句:
import QtQuick 2.1
import QtQuick.Window 2.1
import QtQuick.Controls 1.1
import QtQuick.XmlListModel 2.0
Window {
width: 538 + frame.margins * 2
height: 360 + frame.margins * 2
ToolBar {
id: toolbar
width: parent.width
}
SystemPalette {id: syspal}
color: syspal.window
Rectangle {
anchors.top: toolbar.bottom
anc