linux初探

首页

应用服务器

Linux技巧

中文文档

Linux初级

服务器源代码

命令详解

Linux技术应用

Linux安全应用

Linux业界新闻

UniX技术文章

Linux编程与内核

Linux数据库

Linux服务器

Linux安装指导

Linux论坛

首页>>Linux编程与内核>>文章正文

在CodeBlock中使用QT

最近一直使用vim写QT的程序,不是很爽,尤其是自动补全。
今天,想起使用CodeBlock来,就下载了一个使用。结果不能够新建QT的工程,真是郁闷,后来google了一下,在一个德国的论坛上看到了类似的问题的一个帖子。
说是修改CodeBlock的一个templates文件就可以了。

找到那个文件:
/usr/share/codeblocks/templates/wizard/qt4下面有一个wizard.script。
就是它了。

因为我的QT不是源码编译的,是apt-get 回来的,所以分布比较乱,是按照debian的目录分布的,但是CodeBlock是按照所有的文件分布在一个目录下来进行配置的,所以新建工程的时候会出问题。

apt-get回来的QT的目录在/usr/share/qt4,需要在目录下面有include和lib,QT编译的include在/usr/include/qt4下面,连接库在/usr/lib下面。
修改了之后,再次新建工程,发现在lib选项上出问题了,提示lib必须为.a或者是.lib结尾的文件,真是郁闷。

写了一个脚本自动的将.so文件做一个链接。

QUOTE:
#!/bin/sh
#
#Author:wangyao @ 07-01-04
#Make link for Qt library for CodeBlocks
#
#

for old in $(ls /usr/lib/libQt*.so)
do
echo $old
new=$(echo $old | sed 's/.so/.a/')
echo $new
ln -s $old $new
done

运行后就将QT编译需要的一些库做了链接,再新建工程,好使了。

试着写了一个程序,编译一下,link的时候出错了???
原来它连接的是-lQtCore4,如果你从命令行里面编译的话,就会看到是-lQtCore,改一下工程的属性就可以了。如果想一劳永逸的话,就去改一下上面提到的那个文件,将链接库中去掉"4".

下面是我改过的那个wizard.script:
QUOTE:
////////////////////////////////////////////////////////////////////////////////
//
// Qt4 project wizard
//
////////////////////////////////////////////////////////////////////////////////

// globals
QtPathDefault <- _T("$(#qt)");
QtPathDefaultInc <- _T("$(#qt.include)");
QtPathDefaultLib <- _T("$(#qt.lib)");
QtPath <- _T("");

function BeginWizard()
{
local intro_msg = _T("Welcome to the new Trolltech Qt4 project wizard!\n" +
"This wizard will guide you to create a new Qt4 project\n" +
"using the Trolltech Qt4 cross-platform GUI toolkit\n\n" +
"When you're ready to proceed, please click \"Next\"...");

local qtpath_msg = _T("Please select the location of Trolltech Qt4 on your computer.\n" +
"This is the top-level folder where Qt4 was installed.\n" +
"To help you, this folder must contain the subfolders\n" +
"\"include\" and \"lib\".");

Wizard.AddInfoPage(_T("QtIntro"), intro_msg);
Wizard.AddProjectPathPage();
Wizard.AddGenericSelectPathPage(_T("QtPath"), qtpath_msg, _T("Qt's location:"), QtPathDefault);
Wizard.AddCompilerPage(_T(""), _T("gcc*"), true, true);
}

////////////////////////////////////////////////////////////////////////////////
// Qt's path page
////////////////////////////////////////////////////////////////////////////////

function OnLeave_QtPath(fwd)
{
if (fwd)
{
local dir = Wizard.GetTextControlValue(_T("txtFolder")); // txtFolder is the text control in GenericSelectPathPage
local dir_nomacro = VerifyDirectory(dir);

if (dir_nomacro.IsEmpty())
return false;

// verify include dependencies
local dir_nomacro_inc = GetCompilerIncludeDir(dir, QtPathDefault, QtPathDefaultInc);
if (dir_nomacro_inc.IsEmpty())
return false;
if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("QtGui"), _T("QApplication"), _T("Qt's include"))) return false;

// verify library dependencies
local dir_nomacro_lib = GetCompilerLibDir(dir, QtPathDefault, QtPathDefaultLib);
if (dir_nomacro_lib.IsEmpty())
return false;
//Edit by wangyao at 07-01-04
if (!VerifyLibFile(dir_nomacro_lib, _T("QtCore"), _T("Qt's"))) return false;


QtPath = dir; // Remember the original selection.

local is_macro = _T("");

// try to resolve the include directory as macro
is_macro = GetCompilerIncludeMacro(dir, QtPathDefault, QtPathDefaultInc);
if (is_macro.IsEmpty())
{
// not possible -> use the real inc path we had computed instead
QtPathDefaultInc = dir_nomacro_inc;
}

// try to resolve the library directory as macro
is_macro = GetCompilerLibMacro(dir, QtPathDefault, QtPathDefaultLib);
if (is_macro.IsEmpty())
{
// not possible -> use the real lib path we had computed instead
QtPathDefaultLib = dir_nomacro_lib;
}
}
return true;
}

// return the files this project contains
function GetFilesDir()
{
return _T("qt4/files");
}

// setup the already created project
function SetupProject(project)
{
project.AddIncludeDir(QtPathDefaultInc);
project.AddIncludeDir(QtPathDefaultInc + wxFILE_SEP_PATH + _T("QtGui"));

project.AddLibDir(QtPathDefaultLib);

// add link libraries
//Edit by wangyao at 07-01-04
project.AddLinkLib(_T("QtCore"));
project.AddLinkLib(_T("QtGui"));

// enable compiler warnings (project-wide)
WarningsOn(project, Wizard.GetCompilerID());

// Debug
local target = project.GetBuildTarget(Wizard.GetDebugName());
if (!IsNull(target))
{
target.SetTargetType(ttConsoleOnly); // ttConsoleOnly: console for debugging
target.SetOutputFilename(Wizard.GetDebugOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
// enable generation of debugging symbols for target
DebugSymbolsOn(target, Wizard.GetCompilerID());
}

// Release
target = project.GetBuildTarget(Wizard.GetReleaseName());
if (!IsNull(target))
{
target.SetTargetType(ttExecutable); // ttExecutable: no console
target.SetOutputFilename(Wizard.GetReleaseOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
// enable optimizations for target
OptimizationsOn(target, Wizard.GetCompilerID());
}

return true;
}

我只是改变了两个地方。

相关文章

·在Linux系统下实现定时器
·linux进程通信-信号量使用
·GCC编译优化设置
·Linux内核启动地址
·linux下JDK的安装
·Debian下安装manpages-dev
·Linux下C语言编程基础(Makefile)
·升级SUSE Linux内核的完整步骤
·debian下 编译Emacs 23

热门文章

·C++中控制Windows关机的实用
·C++继承性应用实例 日期和时
·C++类型转换时定义非成员函数
·从模板中分离出参数无关的代
·C++中用函数模板实现和优化抽
·用C++ Builder检测Windows的
·用C++ Builder来定制系统菜单
·C++语言代码检查工具PC-Lint
·用C语言实现常见的三种中文内
·用C++ Builder开发多层数据库

Copyright@2005 www.linuxGoo.com All Right Reserved