在OSX 10.8.2下搭建Qt 4.8.3开发环境



前几天,我把iMac420上的OSX 10.6.8升级成了OSX 10.8.2,所以需要在OSX 10.8.2下重新搭建Qt开发环境。

 

搭建Qt开发环境有两种方法,第一种是直接从http://qt-project.org/downloads下载Qt SDK集成安装包,该集成安装包包含了Qt Creator和Qt库的模拟器版、桌面版、移动版等多个版本,比如:

The�0�2Qt SDK version 1.2.1�0�2released on�0�2April 11th�0�2contains:

  • Qt libraries version 4.8.1
  • Simulator for Symbian phones and the Nokia N9
  • Qt Creator IDE version 2.4.1
  • Qt Mobility version 1.2
  • Qt development tools
  • Remote compilers

 

第二种是从http://qt-project.org/downloads分别下载Qt Creator和Qt库,分别安装。相对于第一种方法,第二种方法至少有以下好处:

(1)你得到的Qt Creator和Qt库的版本一般比第一种方法Qt SDK集成安装包中的Qt Creator和Qt库的版本要新;

(2)你可以自己编译Qt源代码,从而得到Debug版本的Qt库,这样调试Qt应用程序时,可以跟踪到Qt库的内部;

(3)没有Qt库的模拟器版、移动版等多余的东西。对于仅仅开发桌面应用来说,这些是多余的,Nokia想通过集成这些,以推广Symbian开发环境,似乎不是很成功:Symbian现在被Android和iOS打得够呛,Nokia的手机销量也大大下滑;Qt原本是挪威Trolltech公司的,前几年被Nokia收购后,最近又被Nokia卖给了Digia公司(Digia is a Finnish software solutions and service company.�0�2)。

 

目前,最新的Qt SDK版本是1.2.1,里面包含了Qt 4.8.1和Qt Creator 2.4.1,而最新的Qt库是4.8.3版,最新的Qt Creator是2.5.2版。我采用的是第二种方法在OSX 10.8.2下搭建Qt 4.8.3开发环境。

 

(1)从http://qt-project.org/downloads下载和安装下面三个软件包,安装顺序随意:

qt-creator-mac-opensource-2.5.2.dmg

qt-mac-opensource-4.8.3-debug-libs.dmg

qt-mac-opensource-4.8.3.dmg

其实不安装qt-mac-opensource-4.8.3-debug-libs.dmg也是可以的,只是得不到Qt库的debug版,调试Qt应用时,不能跟踪到Qt库内部。注意:不安装qt-mac-opensource-4.8.3.dmg,而只安装qt-mac-opensource-4.8.3-debug-libs.dmg是不行的,后者的安装过程弹出的对话框(如图1所示)说得很清楚:

Note: This package only includes the debug libraries and not the full�0�2
Qt framework. Please also install the non-debug package.
After a successful install, you can find most new things in /Developer. 
图1、只安装qt-mac-opensource-4.8.3-debug-libs.dmg是不行的
�0�2

(2)Qt Creator编译、调试环境的配置

其实,这一条才是我要重点说的。完成步骤(1)后,需要在Qt Creator->Tools->External->Configure->Build & Run->Qt Versions中指定Qt版本。这个简单,只需要指定qmake所在的位置就可以了。由于我的OSX 10.8.2是新装的,没有安装Xcode,所以Qt Creator找不到Tools Chains,提示“No tool chain can produce code for this Qt version”,仍然不能够在Qt Creator中创建工程。我于是又安装了Xcode 4.5,但Qt Creator仍然找不到工具链,这个问题卡了我几个小时。最后在google上搜索到老外的一篇文章,虽然不是讲Qt 4.8.3或者Xcode 4.5的,但文中的下列内容提示了我:

When installing Xcode 4.3, it will offer to clean up existing previous Xcode installations. This is recommended, since before 4.3, the Xcode package installed elements of itself in various locations on the file system. If those are left behind they may be detected erroneously later on and create conflicts. Once this step is complete, the /Developer directory will be gone. This is where the trouble starts if, for example, the Mac OSX SDK was selected in QMake .pro files by its path, as recommended�0�2here.

Before that can be fixed, the Unix command line tools need to be installed. Previously, those were an optional part of the Xcode installation. They now need to be installed from within Xcode. The upside is that Xcode will also automatically check for updates to the tools now, which it did not do before. After the installation is complete, run Xcode, go to Preferences->Downloads, and in the Components tab install the command line tools. You now have a make tool again.

 

于是,我找上面提示安装了command line toolsd,参看图2、图3,然后再次运行Qt Creator,就可以自动检测到工具链了!就这样,在OSX 10.8.2下搭建Qt 4.8.3开发环境成功。:)

图2、运行Xcode 4.5后,找到Preference菜单

 

图3、Command Line Tools安装菜单

 

参考:

在OS X 10.6.8下安装qt-4.8.3及qt-creator-2.5.2

前几天,我把iMac420上的OSX 10.6.8升级成了OSX 10.8.2,所以需要在OSX 10.8.2下重新搭建Qt开发环境。

 

搭建Qt开发环境有两种方法,第一种是直接从http://qt-project.org/downloads下载Qt SDK集成安装包,该集成安装包包含了Qt Creator和Qt库的模拟器版、桌面版、移动版等多个版本,比如:

The�0�2Qt SDK version 1.2.1�0�2released on�0�2April 11th�0�2contains:

  • Qt libraries version 4.8.1
  • Simulator for Symbian phones and the Nokia N9
  • Qt Creator IDE version 2.4.1
  • Qt Mobility version 1.2
  • Qt development tools
  • Remote compilers

 

第二种是从http://qt-project.org/downloads分别下载Qt Creator和Qt库,分别安装。相对于第一种方法,第二种方法至少有以下好处:

(1)你得到的Qt Creator和Qt库的版本一般比第一种方法Qt SDK集成安装包中的Qt Creator和Qt库的版本要新;

(2)你可以自己编译Qt源代码,从而得到Debug版本的Qt库,这样调试Qt应用程序时,可以跟踪到Qt库的内部;

(3)没有Qt库的模拟器版、移动版等多余的东西。对于仅仅开发桌面应用来说,这些是多余的,Nokia想通过集成这些,以推广Symbian开发环境,似乎不是很成功:Symbian现在被Android和iOS打得够呛,Nokia的手机销量也大大下滑;Qt原本是挪威Trolltech公司的,前几年被Nokia收购后,最近又被Nokia卖给了Digia公司(Digia is a Finnish software solutions and service company.�0�2)。

 

目前,最新的Qt SDK版本是1.2.1,里面包含了Qt 4.8.1和Qt Creator 2.4.1,而最新的Qt库是4.8.3版,最新的Qt Creator是2.5.2版。我采用的是第二种方法在OSX 10.8.2下搭建Qt 4.8.3开发环境。

 

(1)从http://qt-project.org/downloads下载和安装下面三个软件包,安装顺序随意:

qt-creator-mac-opensource-2.5.2.dmg

qt-mac-opensource-4.8.3-debug-libs.dmg

qt-mac-opensource-4.8.3.dmg

其实不安装qt-mac-opensource-4.8.3-debug-libs.dmg也是可以的,只是得不到Qt库的debug版,调试Qt应用时,不能跟踪到Qt库内部。注意:不安装qt-mac-opensource-4.8.3.dmg,而只安装qt-mac-opensource-4.8.3-debug-libs.dmg是不行的,后者的安装过程弹出的对话框(如图1所示)说得很清楚:

Note: This package only includes the debug libraries and not the full�0�2
Qt framework. Please also install the non-debug package.
After a successful install, you can find most new things in /Developer. 
图1、只安装qt-mac-opensource-4.8.3-debug-libs.dmg是不行的
�0�2

(2)Qt Creator编译、调试环境的配置

其实,这一条才是我要重点说的。完成步骤(1)后,需要在Qt Creator->Tools->External->Configure->Build & Run->Qt Versions中指定Qt版本。这个简单,只需要指定qmake所在的位置就可以了。由于我的OSX 10.8.2是新装的,没有安装Xcode,所以Qt Creator找不到Tools Chains,提示“No tool chain can produce code for this Qt version”,仍然不能够在Qt Creator中创建工程。我于是又安装了Xcode 4.5,但Qt Creator仍然找不到工具链,这个问题卡了我几个小时。最后在google上搜索到老外的一篇文章,虽然不是讲Qt 4.8.3或者Xcode 4.5的,但文中的下列内容提示了我:

When installing Xcode 4.3, it will offer to clean up existing previous Xcode installations. This is recommended, since before 4.3, the Xcode package installed elements of itself in various locations on the file system. If those are left behind they may be detected erroneously later on and create conflicts. Once this step is complete, the /Developer directory will be gone. This is where the trouble starts if, for example, the Mac OSX SDK was selected in QMake .pro files by its path, as recommended�0�2here.

Before that can be fixed, the Unix command line tools need to be installed. Previously, those were an optional part of the Xcode installation. They now need to be installed from within Xcode. The upside is that Xcode will also automatically check for updates to the tools now, which it did not do before. After the installation is complete, run Xcode, go to Preferences->Downloads, and in the Components tab install the command line tools. You now have a make tool again.

 

于是,我找上面提示安装了command line toolsd,参看图2、图3,然后再次运行Qt Creator,就可以自动检测到工具链了!就这样,在OSX 10.8.2下搭建Qt 4.8.3开发环境成功。:)

图2、运行Xcode 4.5后,找到Preference菜单

 

图3、Command Line Tools安装菜单

 

参考:

在OS X 10.6.8下安装qt-4.8.3及qt-creator-2.5.2

  1. 注意图1 已经提示了Qt-Debug-Lib 的卸载脚本的位置在 /Developer/Tools/uninstall-qt.py

    不注意这一点,以后卸载Qt时,找不到卸载脚本。

    安装 Qt-Lib 的卸载脚本也在其安装程序对话框中有提示,可以看出,两者共用同一个卸载脚本:
    /Developer/Tools/uninstall-qt.py

    Reply
  2. 梦里嗣音  says:

    qmake 默认被安装到 /usr/bin 路径下,这会给配置Qt版本带来一点小麻烦:

    在Mac图形界面中,一般是不显示 /usr 等系统目录的,这就造成你在
    “Qt Creator->Tools->External->Configure->Build & Run->Qt Version”
    对话框中无法指定 qmake 路径。

    我想出了一个办法解决:

    先在个人目录下建立 bin 目录,然后从命令行拷贝 /usr/bin/qmake 到 ~/bin 目录下,再在 “Qt Creator->Tools->External->Configure->Build & Run->Qt Version” 对话框中指定 qmake 为 ~/bin/qmake,最后将 “~/.config/QtProject/qtcreator/qtversion.xml” 文件中的 “~/bin/qmake” 改成 “/usr/bin/qmake” 即可。补充提示一点:由于.config 是隐含目录,一般在图形界面下,找不到该目录及其下属文件,可以通过命令行模式下,用 vi 修改,即执行
    “vi ~/.config/QtProject/qtcreator/qtversion.xml” 命令修改。


你可能感兴趣的:(qt)