7

我正在尝试使用来自http://labs.qt.nokia.com/2011/03/10/qml-components-for-desktop/的 Qt Quick Components for Desktop

我可以将它构建并安装到它自己的文件夹中,并使用 qmlviewer 查看 qmls,但是如何在 Qt Creator 中使用其他项目中的这些 qml 组件?

例如,我希望能够使用 Qt Quick Components for Desktop 中的 Dial.qml 在我的项目的 qml 文件中创建 Dial 元素。

4

3 回答 3

8

我使用了这个问题的答案中的说明:Qt How to make and install plugins? 并且能够成功使用 qt creator qml 文件中的 qt 快速桌面组件。以下是我制作的更详细的说明:

  1. 从http://qt.gitorious.org/qt-components/desktop/trees/master下载 tar.gz
  2. 在任何地方提取组件(例如 C:\qt-components-desktop)。
  3. 打开命令提示符。
  4. 在命令提示符下从“your Visual Studio”\VC\bin\ 目录...(通常是 C:\Program Files\Microsoft Visual Studio 9.0\VC\bin)运行 vcvars32.bat。例如“C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat” 您应该会收到类似于“使用 Microsoft Visual Studio 2008 x86 工具的设置环境”的消息
  5. 设置命令提示符以使用 Qt Creator 的 bin 路径 ...(通常为 C:\Qt\qtcreator-2.1.0\bin)。例如 SET PATH=%PATH%;C:\Qt\qtcreator-2.1.0\bin
  6. 设置命令提示符以使用 Qt 的 bin 路径 ...(通常为 C:\Qt\4.7.2\bin)。例如 SET PATH=%PATH%;C:\Qt\4.7.2\bin
  7. 在命令提示符中导航到您提取 qt 桌面组件的文件夹。
  8. 运行以下命令: qmake jom debug jom install
  9. 从您提取 qt 桌面组件的位置复制“组件”文件夹。
  10. 把它放在“你的Qt目录”\imports\Qt\labs ...(通常是C:\Qt\4.7.2\imports\Qt\labs)
  11. 在任何文本编辑器中打开 components 文件夹中的 qmldir 文件并观察每一行的版本号(例如 0.1)
  12. 将以下导入语句放在任何 qml 文件中以使用 Qt 桌面组件: import Qt.labs.components #.# 其中 #.# 是您的版本号(例如 0.1)
于 2011-06-10T16:11:26.747 回答
3
  1. 从http://qt.gitorious.org/qt-components/desktop/trees/master下载 tar.gz
  2. 打开包装
  3. 启动 vcvars32.bat,然后转到 qt-components-desktop\ 文件夹
  4. 转到 qt-components-desktop\components\ 文件夹(cd 组件),键入“qmake && nmake install”
  5. 转到 qt-components-desktop\src\ 文件夹,键入“qmake && nmake install”
于 2012-02-27T11:59:58.317 回答
0

这些是使用 Windows 系统和 Qt 附带的 mingw 的替代步骤。对于此示例,我将 Qt SDK 安装到C:\QtSDK. 对于这些说明,我使用了 Qt 4.8.1。

  1. 从http://qt.gitorious.org/qt-components/desktop/trees/master下载 tar.gz
  2. 拆开组件
  3. 使用以下两个选项之一将 Qt 的桌面 mingw bin 路径和 Qt 的 mingw bin 路径添加到 PATH 系统变量:
    • 选项 1:(持久)使用控制面板。http://www.computerhope.com/issues/ch000549.htm
      1. 导航到“控制面板”->“系统”->“高级系统设置”
      2. 选择“高级”选项卡
      3. 按“环境变量...”按钮,位于第三组框下方和确定/取消按钮上方
      4. 在“系统变量”组框下,滚动列表并找到“路径”变量
      5. 双击或选择“路径”变量,然后按“编辑...”
      6. 通过在字段中单击并按键盘上的 END 或用鼠标滚动到末尾,转到“变量值:”字段的最右端。
      7. 添加分号;,然后添加 Qt 的 mingw bin 目录的路径,在本例中为C:\QtSDK\mingw\bin
      8. 在末尾添加另一个分号,然后在您使用的 Qt 版本中添加 Qt 的 Desktop mingw bin 目录,在本例中为 4.8.1:;C:\QtSDK\Desktop\Qt\4.8.1\mingw\bin
      9. 最后,路径变量的添加应该如下所示;C:\QtSDK\mingw\bin;C:\QtSDK\Desktop\Qt\4.8.1\mingw\bin:请注意,这些路径也可以添加到路径变量中的任何位置和任何顺序。
      10. 按“确定”关闭所有打开的窗口并保存您的更改。
    • 选项 2:(临时)使用 SET 命令。此方法仅在其执行的命令提示符窗口内持续存在。如果命令提示符窗口关闭,则必须重新输入 SET 命令。
      1. 添加 Qt 的桌面 mingw bin 目录SET PATH=%PATH%;C:\QtSDK\Desktop\Qt\4.8.1\mingw\bin
      2. 添加 Qt 的 mingw bin 目录SET PATH=%PATH%;C:\QtSDK\mingw\bin
      3. 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.
  4. 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
  5. Run the following command: qmake && mingw-make install
  6. 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.
  7. Make a new Qt Desktop project, and select the mingw which matches the Qt version as the toolchain.
  8. 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"
        }
    }
    
  9. 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.

于 2012-04-12T18:17:25.150 回答