Ubuntu 平台上用 Code::Blocks 编译 Qt4 程序


1.Qt4 安装过程
$ sudo apt-get install libqt4-dev libqt4-dbg libqt4-gui libqt4-sql qt4-dev-tools qt4-doc qt4-designer qt4-qtconfig

2.新建 Qt4 工程时只需注意此两项设置:
  Qt's location: /usr
  "Debug/Release" options 的 Output dir.: 与 Objects output dir.: 设为空,即为工程根目录。

3.对于需要使用到 Q_OBJECT 宏的时候,直接 Build 就会报错,我们需要使用 Qmake :
点击菜单 [Tools] -> [Configure tools...] 添加两个新工具:
1)
Name: Create Qt Project File
Executable:/usr/share/qt4/bin/qmake <-- 即本机上 qmake 的绝对路径
Parameters: -project
Working directory: ${PROJECT_DIR}
Launching options 选择 Launch tool hidden with standard output redirected
注:这样就不会弹出命令行窗口。
点 确定 按钮完成。

2)
Name: Create Qt Makefile
Executable:/usr/share/qt4/bin/qmake <-- 即本机上 qmake 的绝对路径
Parameters: -makefile
Working directory: ${PROJECT_DIR}
Launching options 选择 Launch tool hidden with standard output redirected
注:这样就不会弹出命令行窗口。
点 确定 按钮完成。

4.点击菜单[Project] -> [Properties...] -> [Project settings],
  在"This is a custom Makefile"前打勾,这样可以使用自定义的 Makefile 了。

5.点击上面的"Build targets"选项页,
  将"Type:"下拉列表框改为"GUI application"。

6.点击菜单[Project] -> [Build options...] -> "Make" commands 选项页,删除所有 $target 。

以上均设置好后,在编译之前使用一下 Create Qt Project File 和 Create Qt Makefile 两个工具,
再 build 就可以了。

Code::Blocks 的详细介绍:请点这里
Code::Blocks 的下载地址:请点这里

相关内容