壹、$ sudo apt-get install libqt4-dev libqt4-debug libqt4-gui
libqt4-sql qt4-dev-tools qt4-doc qt4-designer qt4-qtconfig
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 在安裝這個軟件的時候系統提示:
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關系樹
正在讀取狀態信息...
完成
三、編寫源代碼。 新建文件夾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的小窗口安裝完畢