歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu 12.04下安裝QT 4.0

Ubuntu 12.04下安裝QT 4.0

日期:2017/2/28 15:51:00   编辑:Linux教程

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

運行:

一、$ sudo apt-get install libqt4-dev libqt4-debug 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界面的設計器

注意

二、$ sudo apt-get install libqt4-debug 在安裝這個軟件的時候系統可能提示:
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關系樹
正在讀取狀態信息... 完成
現在沒有可用的軟件包 libqt4-debug,但是它被其它的軟件包引用了。
這可能意味著這個缺失的軟件包可能已被廢棄,
或者只能在其他發布源中找到
可是下列軟件包取代了它:
libqt4-dbg:i386 libqt4-dbg
所以這時候我們采用
$ sudo apt-get install libqt4-dbg代替
等到全部安裝完畢後,我們來用一個程序試試

三、首先編寫源代碼。 新建文件夾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的小窗口,至此安裝完畢

更多Ubuntu相關信息見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2

Copyright © Linux教程網 All Rights Reserved