講解在Linux下配置QT 學習之路
本文介紹的是講解在Linux下配置QT 學習之路,我們首先來看內(nèi)容。在CentOS下配置QT:通過yum search qt,得知源上可以安裝的QT軟件列表如下(有很多QT組件可以選擇安裝):
qt.i386 : Qt GUI 工具包的共享庫。
qt-MySQL.i386 : 用于 Qt 的 SQL 類別的 MySQL 驅(qū)動程序。
qt-ODBC.i386 : 用于 Qt 的 SQL 類別的 ODBC 驅(qū)動程序。
qt-PostgreSQL.i386 : 用于 Qt 的 SQL 類別的 PostgreSQL 驅(qū)動程序。
qt-config.i386 : 為使用 Qt 的程序提供的圖形化配置工具。
qt-designer.i386 : Qt GUI 工具包的界面設(shè)計程序 (IDE)
- qt-devel.i386 : Development files for the Qt GUI toolkit.
- qt-devel-docs.i386 : Documentation for the Qt GUI toolkit.
- wpa_supplicant-gui.i386 : Graphical User Interface for wpa_supplicant
PyQt.i386 : Qt 的 Python 綁定
PyQt-devel.i386 : 要建構(gòu)基于 Qt 的其它綁定所需的文件
PyQt-examples.i386 : PyQt 的樣例
- avahi-qt3.i386 : Qt3 libraries for avahi // avahi是什么東西?
- avahi-qt3-devel.i386 : Libraries and header files for avahi Qt3 development
- pinentry-qt.i386 : Passphrase/PIN entry dialog based on Qt
- qt4.i386 : The shared library for the Qt GUI toolkit
- qt4-devel.i386 : Development files for the Qt GUI toolkit
- qt4-doc.i386 : API documentation, demos and example programs for qt4
- qt4-mysql.i386 : MySQL drivers for Qt's SQL classes
- qt4-odbc.i386 : ODBC drivers for Qt's SQL classes
- qt4-postgresql.i386 : PostgreSQL drivers for Qt's SQL classes
- qt4-sqlite.i386 : SQLite drivers for Qt's SQL classes
- qtnx.i386 : QT4 based FreeNX Client
scim-qtimm.i386 : Qt 的 SCIM 輸入法模塊 // 這個是SCIM模塊,用Qt實現(xiàn)的吧?
- scribus.i386 : DeskTop Publishing application written in Qt
- sip.i386 : SIP - Python/C++ 綁定生成器.
通過rpm命令查詢已經(jīng)安裝的Qt軟件:
- [root@Tomato ~]# rpm -qa | grep qt
- qt-3.3.6-23.el5
- scim-qtimm-0.9.4-5
- avahi-qt3-0.6.16-6.el5 // Qt3和Qt4可以同時共存嗎?
Linux上編譯居然因為環(huán)境變量,而報錯:
- QMAKESPEC has not been set, so configuration cannot be deduced.
- Error processing project file: /root/qt/qt.pro
在腳本里加入該環(huán)境變量,這個錯誤已經(jīng)消失:
- [root@localhost qt]# ls
- hello.cpp
- [root@localhost qt]# qmake -project
- [root@localhost qt]# ls
- hello.cpp qt.pro
- [root@localhost qt]# qmake
- [root@localhost qt]# ls
- hello.cpp Makefile qt.pro
Make報如下錯誤:
- [root@localhost qt]# make
- g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB
- -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/mkspecs/linux-g++ -I.
- -I/work/program/qtdevelop/include/QtCore -I/work/program/qtdevelop/include/QtGui
- -I/work/program/qtdevelop/include -I. -I. -o hello.o hello.cpp
- hello.cpp:1:24: 錯誤:QApplication:沒有那個文件或目錄
- hello.cpp:2:18: 錯誤:QLabel:沒有那個文件或目錄
- hello.cpp: In function ‘int main(int, char**)’:
- hello.cpp:6: 錯誤:‘QApplication’ 在此作用域中尚未聲明
- hello.cpp:6: 錯誤:expected `;' before ‘app’
- hello.cpp:7: 錯誤:‘QLabel’ 在此作用域中尚未聲明
- hello.cpp:7: 錯誤:‘label’ 在此作用域中尚未聲明
- hello.cpp:7: 錯誤:expected type-specifier before ‘QLabel’
- hello.cpp:7: 錯誤:expected `;' before ‘QLabel’
- hello.cpp:9: 錯誤:‘app’ 在此作用域中尚未聲明
- hello.cpp: At global scope:
- hello.cpp:4: 警告:未使用的參數(shù) ‘argc’
- hello.cpp:4: 警告:未使用的參數(shù) ‘argv’
- make: *** [hello.o] 錯誤 1
生成的Makefile有些問題:
- CC = gcc
- CXX = g++
- DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB
- CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
- CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
- INCPATH = -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/mkspecs/l
- inux-g++ -I. -I/work/program/qtdevelop/include/QtCore -I/work/program/qtdevelop/
- include/QtGui -I/work/program/qtdevelop/include -I. -I. // 這個路徑是怎么生成的?.
- LINK = g++
- LFLAGS = -Wl,-O1
- LIBS = $(SUBLIBS) -L/work/program/qtdevelop/lib -lQtGui -lQtCore -lpth
- read
簡單文件運行出錯:
- [root@localhost c++]# ./a.out
- -bash: ./a.out: cannot execute binary file // 剛開始出這個錯是什么原因啊?重新編譯后就正常了。。。
- [root@localhost c++]# file a.out
- a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9,
- dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
修改Makefile之后,文件編譯成功,但是運行仍然是報錯的:
- [root@localhost qt]# make
- g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB
- -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/mkspecs/linux-g++ -I.
- -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/include/QtCore
- -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/include/QtGui
- -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/include -I. -I. -o hello.o hello.cpp
- g++ -Wl,-O1 -o qt hello.o -L/work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib -lQtGui -lQtCore -lpthread
- [root@localhost qt]# ls
- hello.cpp hello.o Makefile qt qt.pro
- [root@localhost qt]# ./qt
- ./qt: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory
100216 缺少這個動態(tài)鏈接庫,如何辦?: 可以直接在路徑里加上嗎?
- [root@localhost qt]# find /work/program/dsk/qt-everywhere-opensource-src-4.6.1/ | grep libQtGui.so.4
- /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib/libQtGui.so.4.6.1
- /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib/libQtGui.so.4.6.1.debug
- /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib/libQtGui.so.4.6
- /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib/libQtGui.so.4
ld文件配置:
- /etc/ld.so.conf
- include ld.so.conf.d/*.conf // 里面只有一行配置,表示去ld.so.conf.d目錄中尋找配置信息。
- /etc/ld.so.conf.d/qt-i386.conf 這里的配置信息為:usr/lib/qt-3.3/lib,指向老的qt配置。
- /etc/ld.so.conf.d/mysql-i386.conf // 怎么只有兩個ld配置文件?
- usr/lib/mysql
這個目錄下還有很多配置文件:
- [root@localhost mkspecs]# pwd
- /work/program/dsk/qt-everywhere-opensource-src-4.6.1/mkspecs
Qt庫文件的實際位置:
- [root@localhost lib]# du -sh
- 425M .
- [root@localhost lib]# pwd
- /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib.
設(shè)置完ld路徑后,運行成功第一個Qt程序。。。:
現(xiàn)在的ld.so.conf.d下的qt配置內(nèi)容如下:
- #/usr/lib/qt-3.3/lib // 之后需要運行l(wèi)dconfig命令。
- /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib
ld設(shè)置后,基于Qt的應(yīng)用啟動不了。。。:
把/usr/lib/qt-3.3/lib注釋掉,只配置下面的選項(運行基于qt-3.3的應(yīng)用程序出錯,在界面是跳出報錯窗口)。
- /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib
在命令行報出的錯誤則有些不同:
- [root@localhost qt]# ksnapshot
- ksnapshot: error while loading shared libraries: libqt-mt.so.3: cannot open shared object file: No such file or directory
小結(jié):關(guān)于講解在Linux下配置QT 學習之路的內(nèi)容介紹完了希望本文對你有所幫助!