您的位置:首页 > 编程语言 > Qt开发

在Ubuntu 12.04下采用apt-get的方法安装Qt4

2012-11-02 17:59 387 查看

Ubuntu 12.04下采用apt-get的方法安装Qt4。

运行:

一、

sudo apt-get install libqt4-dev libqt4-dbg libqt4-gui libqt4-sql qt4-dev-tools qt4-doc qt4-designer qt4-qtconfig


上面列出的是qt配置环境所必须的软件包,比如qt4-dev-tools 包含了Qt Assistant及Qt Linguist等工具,因此不需要单独安装这两个工具。其它的,qt4-doc 是帮助文档,包含了Qt中各个类库的详细说明以及丰富的例子程序,可以使用Qt Assistant 工具来打开阅读。qt4-qtconfig 是配置Qt环境的一个对话框,一般默认就行了,很少有必要去更改。qt4-demos 包含很多可以运行起来的可执行文件以及源代码。qt4-designer是用来设计GUI界面的设计器

等到全部安装完毕后,我们来用一个程序试试

二、、首先编写源代码。 新建文件夹qt4hello,然后再里面新建文件 Qthello.cpp,内容如下:

#include <QApplication> 
#include <QPushButton>    
int main(int argc, char *argv[]) 
{             
    QApplication app(argc, argv);              
    QPushButton hello("Hello Ubuntu!");             
    hello.resize(100, 30);               
    hello.show();             
    return app.exec();  
}


在终端输入:$ gedit Qthello.cpp(输入上面的程序)

$qmake -project(生成Qt项目)

$qmake(生成makefile文件)

$make

出现g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o QtHello.o QtHello.cpp

g++ -o qtsrc QtHello.o -L/usr/lib -lQtGui -lQtCore -lpthread

最后 $ ls

Makefile qt4hello qt4hello.pro Qthello.cpp Qthello.o

接着 $ ./qt4hello 在屏幕上显示一个hello的小窗口,至此安装完毕

参考:http://www.linuxidc.com/Linux/2012-05/60770.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: