这些是使用 Windows 系统和 Qt 附带的 mingw 的替代步骤。对于此示例,我将 Qt SDK 安装到C:\QtSDK
. 对于这些说明,我使用了 Qt 4.8.1。
- 从http://qt.gitorious.org/qt-components/desktop/trees/master下载 tar.gz
- 拆开组件
- 使用以下两个选项之一将 Qt 的桌面 mingw bin 路径和 Qt 的 mingw bin 路径添加到 PATH 系统变量:
- 选项 1:(持久)使用控制面板。(http://www.computerhope.com/issues/ch000549.htm)
- 导航到“控制面板”->“系统”->“高级系统设置”
- 选择“高级”选项卡
- 按“环境变量...”按钮,位于第三组框下方和确定/取消按钮上方
- 在“系统变量”组框下,滚动列表并找到“路径”变量
- 双击或选择“路径”变量,然后按“编辑...”
- 通过在字段中单击并按键盘上的 END 或用鼠标滚动到末尾,转到“变量值:”字段的最右端。
- 添加分号
;
,然后添加 Qt 的 mingw bin 目录的路径,在本例中为C:\QtSDK\mingw\bin
- 在末尾添加另一个分号,然后在您使用的 Qt 版本中添加 Qt 的 Desktop mingw bin 目录,在本例中为 4.8.1:
;C:\QtSDK\Desktop\Qt\4.8.1\mingw\bin
- 最后,路径变量的添加应该如下所示
;C:\QtSDK\mingw\bin;C:\QtSDK\Desktop\Qt\4.8.1\mingw\bin
:请注意,这些路径也可以添加到路径变量中的任何位置和任何顺序。
- 按“确定”关闭所有打开的窗口并保存您的更改。
- 选项 2:(临时)使用 SET 命令。此方法仅在其执行的命令提示符窗口内持续存在。如果命令提示符窗口关闭,则必须重新输入 SET 命令。
- 添加 Qt 的桌面 mingw bin 目录
SET PATH=%PATH%;C:\QtSDK\Desktop\Qt\4.8.1\mingw\bin
- 添加 Qt 的 mingw bin 目录
SET PATH=%PATH%;C:\QtSDK\mingw\bin
- Continue the steps below with this same command prompt window. The SET commands are only set for the specific command prompt window you executed them in.
- If option 1 was used, open a new command prompt and navigate to where the qt desktop components are extracted. If option 2 was used, use the same command prompt to navigate to the qt desktop components folder
- Run the following command:
qmake && mingw-make install
- This command will automatically copy the compiled component files to
C:\QtSDK\Desktop\Qt\4.8.1\mingw\imports\QtDesktop
so there is no need to manually move or create any folders.
- Make a new Qt Desktop project, and select the mingw which matches the Qt version as the toolchain.
Attempt to compile and run the following code:
import QtQuick 1.1
import QtDesktop 0.1
Rectangle {
width: 100
height: 100
Button {
id: button
text: "Push me"
onClicked: button.text = "Pressed"
}
}
- Done
At the time of these instructions, the latest version of the QtDesktop components is 0.1. To check the version you installed, navigate to C:\QtSDK\Desktop\Qt\4.8.1\mingw\imports\QtDesktop
and open the file qmldir
with a text editor and notice the version number on each line.