当前位置:文档之家› Linux 下 Qt Creator 的安装使用

Linux 下 Qt Creator 的安装使用

Linux 下Qt Creator 的安装使用
Qt 以其开源,免费,完全面向对象(很容易扩展),允许真正的组件编程以及可移植跨平台等诸多优势得到越来越多的开发人员的青睐。

Qt Creator 是Nokia 官方推出的专门针对Qt 开发的IDE。

本文详细介绍了Linux 下Qt Creator 的安装,并针对Qt Creator 的使用举了一个Hello World 级别的例子,希望对第一次接触Qt Creator 的朋友可以起到抛砖引玉的作用。

Qt Creator 安装
1。

准备
下载并安装好Qt(关于Qt 的编译并安装配置,请参考作者的前一篇博客《Linux 下编译并安装配置Qt 全过程》)。

2。

查看
查看自己电脑系统情况,终端输入命令:
uname -a
作者的是x86_64 GNU/Linux。

3。

下载
到Qt 官方网站下载与自己电脑相配套的Qt Creator,地址是/downloads。

Qt Creator 的最新版本是 1.3.0,作者选择的是Qt Creator 1.3.0 Binary for Linux/X11 64-bit (48 MB)。

4。

安装
下载后得到大小47.2 Mb 的安装文件qt-creator-linux-x86_64-opensource-1.3.0.bin,在Linux 上安装如下:
chmod u+x ./qt-creator-linux-x86_64-opensource-1.3.0.bin
./qt-creator-linux-x86_64-opensource-1.3.0.bin
这时候,启动了Setup Qt Creator 欢迎安装对话框,点击“Next”->
协议许可界面,选择“I accept the agreement”,点击“Next” ->
选择Qt Creator 安装目录对话框。

作者选择的是/home/defonds/TOOLS/qtcreator/qtcreator-1.3.0,点击“Next” ->
准备安装界面,点击“Next” ->
安装结束,点击“Finish”。

Qt Creator 使用
新建项目HelloWorld
启动桌面上的Qt Creator。

新建工程HelloWorld,菜单点击“File” -> New File or Project... -> Projects 中选择Empty Qt4 Project -> OK -> 项目名键入HelloWorld,工作台随意,作者选择的是
/home/defonds/cpp/qt ,Next -> Finish。

新建类Hello
右键单击项目名HelloWorld,Add New... -> C++ 下选择C++ Source File,点击“OK” -> 输入类名Hello 点击“Next” -> Finish。

这个时候Hello.cpp 被创建,双击它进行编辑,编辑内容仍采用上一篇博客《Linux 下编译并安装配置Qt 全过程》中的例子,其内容如下:
1. #include <QApplication>
2. #include <QLabel>
3. int main( int argc, char *argv[])
4. {
5. QApplication app(argc,argv);
6. QLabel *label = new QLabel( "Hello Qt!" );
7. label->show();
8. return app.exec();
9. }
view plaincopy to clipboardprint?
1. #include <QApplication>
2. #include <QLabel>
3. int main(int argc,char *argv[])
4. {
5. QApplication app(argc,argv);
6. QLabel *label = new QLabel("Hello Qt!");
7. label->show();
8. return app.exec();
9. }
#include <QApplication> #include <QLabel> int main(int argc,char *argv[]) { QApplication app(argc,argv);
QLabel *label = new QLabel("Hello Qt!"); label->show(); return app.exec(); }
保存,菜单栏选择Build -> Run,“Hello Qt!”对话框弹出,证明你写的Qt 程序编译OK。

这个时候,在/home/defonds/cpp/qt/HelloWorld 目录下有个可执行文件HelloWorld 被生成,双击它,就可以弹出“Hello Qt!”对话框。

它就是你在Linux 下使用Qt Creator 开发出的第一个Qt 项目。

转自:/defonds/archive/2009/12/05/4946472.aspx。

相关主题