讲解在Linux下配置QT 学习之路

讲解在Linux下配置QT 学习之路

本文介绍的是讲解在Linux下配置QT 学习之路,我们首先来看内容。在CentOS下配置QT:通过yum search qt,得知源上可以安装的QT软件列表如下(有很多QT组件可以选择安装):


qt.i386 : Qt GUI 工具包的共享库。


qt-MySQL.i386 : 用于 Qt 的 SQL 类别的 MySQL 驱动程序。


qt-ODBC.i386 : 用于 Qt 的 SQL 类别的 ODBC 驱动程序。


qt-PostgreSQL.i386 : 用于 Qt 的 SQL 类别的 PostgreSQL 驱动程序。


qt-config.i386 : 为使用 Qt 的程序提供的图形化配置工具。


qt-designer.i386 : Qt GUI 工具包的界面设计程序 (IDE)


 
 
  1. qt-devel.i386 : Development files for the Qt GUI toolkit.  
  2. qt-devel-docs.i386 : Documentation for the Qt GUI toolkit.  
  3. wpa_supplicant-gui.i386 : Graphical User Interface for wpa_supplicant 

PyQt.i386 : Qt 的 Python 绑定


PyQt-devel.i386 : 要建构基于 Qt 的其它绑定所需的文件


PyQt-examples.i386 : PyQt 的样例


 
 
  1. avahi-qt3.i386 : Qt3 libraries for avahi // avahi是什么东西?  
  2.  
  3. avahi-qt3-devel.i386 : Libraries and header files for avahi Qt3 development  
  4. pinentry-qt.i386 : Passphrase/PIN entry dialog based on Qt  
  5. qt4.i386 : The shared library for the Qt GUI toolkit  
  6. qt4-devel.i386 : Development files for the Qt GUI toolkit  
  7. qt4-doc.i386 : API documentation, demos and example programs for qt4  
  8. qt4-mysql.i386 : MySQL drivers for Qt's SQL classes  
  9. qt4-odbc.i386 : ODBC drivers for Qt's SQL classes  
  10. qt4-postgresql.i386 : PostgreSQL drivers for Qt's SQL classes  
  11. qt4-sqlite.i386 : SQLite drivers for Qt's SQL classes  
  12. qtnx.i386 : QT4 based FreeNX Client 

scim-qtimm.i386 : Qt 的 SCIM 输入法模块 // 这个是SCIM模块,用Qt实现的吧?


 
 
  1. scribus.i386 : DeskTop Publishing application written in Qt  
  2. sip.i386 : SIP - Python/C++ 绑定生成器. 

通过rpm命令查询已经安装的Qt软件:


 
 
  1. [root@Tomato ~]# rpm -qa | grep qt  
  2. qt-3.3.6-23.el5  
  3. scim-qtimm-0.9.4-5  
  4. avahi-qt3-0.6.16-6.el5 // Qt3和Qt4可以同时共存吗? 

Linux上编译居然因为环境变量,而报错:


 
 
  1. QMAKESPEC has not been set, so configuration cannot be deduced.  
  2. Error processing project file: /root/qt/qt.pro 

在脚本里加入该环境变量,这个错误已经消失:


 
 
  1. [root@localhost qt]# ls  
  2. hello.cpp  
  3. [root@localhost qt]# qmake -project  
  4. [root@localhost qt]# ls  
  5. hello.cpp qt.pro  
  6. [root@localhost qt]# qmake  
  7. [root@localhost qt]# ls  
  8. hello.cpp Makefile qt.pro 

Make报如下错误:


 
 
  1. [root@localhost qt]# make  
  2. g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB 
  3. -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/mkspecs/linux-g++ -I. 
  4. -I/work/program/qtdevelop/include/QtCore -I/work/program/qtdevelop/include/QtGui 
  5. -I/work/program/qtdevelop/include -I. -I. -o hello.o hello.cpp  
  6. hello.cpp:1:24: 错误:QApplication:没有那个文件或目录  
  7. hello.cpp:2:18: 错误:QLabel:没有那个文件或目录  
  8. hello.cpp: In function ‘int main(int, char**)’:  
  9. hello.cpp:6: 错误:‘QApplication’ 在此作用域中尚未声明  
  10. hello.cpp:6: 错误:expected `;' before ‘app’  
  11. hello.cpp:7: 错误:‘QLabel’ 在此作用域中尚未声明  
  12. hello.cpp:7: 错误:‘label’ 在此作用域中尚未声明  
  13. hello.cpp:7: 错误:expected type-specifier before ‘QLabel’  
  14. hello.cpp:7: 错误:expected `;' before ‘QLabel’  
  15. hello.cpp:9: 错误:‘app’ 在此作用域中尚未声明  
  16. hello.cpp: At global scope:  
  17. hello.cpp:4: 警告:未使用的参数 ‘argc’  
  18. hello.cpp:4: 警告:未使用的参数 ‘argv’  
  19. make: *** [hello.o] 错误 1 

生成的Makefile有些问题:


 
 
  1. CC            = gcc 
  2. CXX           = g++  
  3. DEFINES       = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB  
  4. CFLAGS        = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)  
  5. CXXFLAGS      = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)  
  6. INCPATH       = -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/mkspecs/l  
  7. inux-g++ -I. -I/work/program/qtdevelop/include/QtCore -I/work/program/qtdevelop/  
  8. include/QtGui -I/work/program/qtdevelop/include -I. -I. // 这个路径是怎么生成的?.  
  9. LINK          = g++  
  10. LFLAGS        = -Wl,-O1  
  11. LIBS          = $(SUBLIBS) -L/work/program/qtdevelop/lib -lQtGui -lQtCore -lpth  
  12. read 

简单文件运行出错:


 
 
  1. [root@localhost c++]# ./a.out  
  2. -bash: ./a.out: cannot execute binary file // 刚开始出这个错是什么原因啊?重新编译后就正常了。。。  
  3. [root@localhost c++]# file a.out  
  4. a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, 
  5. dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped 

修改Makefile之后,文件编译成功,但是运行仍然是报错的:


 
 
  1. [root@localhost qt]# make  
  2. g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB 
  3. -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/mkspecs/linux-g++ -I. 
  4. -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/include/QtCore 
  5. -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/include/QtGui 
  6. -I/work/program/dsk/qt-everywhere-opensource-src-4.6.1/include -I. -I. -o hello.o hello.cpp  
  7. g++ -Wl,-O1 -o qt hello.o    -L/work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib -lQtGui -lQtCore -lpthread  
  8. [root@localhost qt]# ls  
  9. hello.cpp hello.o Makefile qt qt.pro  
  10. [root@localhost qt]# ./qt  
  11. ./qt: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory 

100216 缺少这个动态链接库,如何办?: 可以直接在路径里加上吗?


 
 
  1. [root@localhost qt]# find /work/program/dsk/qt-everywhere-opensource-src-4.6.1/ | grep libQtGui.so.4  
  2. /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib/libQtGui.so.4.6.1  
  3. /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib/libQtGui.so.4.6.1.debug  
  4. /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib/libQtGui.so.4.6  
  5. /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib/libQtGui.so.4 

ld文件配置:


 
 
  1. /etc/ld.so.conf  
  2. include ld.so.conf.d/*.conf // 里面只有一行配置,表示去ld.so.conf.d目录中寻找配置信息。  
  3. /etc/ld.so.conf.d/qt-i386.conf 这里的配置信息为:usr/lib/qt-3.3/lib,指向老的qt配置。  
  4. /etc/ld.so.conf.d/mysql-i386.conf // 怎么只有两个ld配置文件?  
  5. usr/lib/mysql 

这个目录下还有很多配置文件:


 
 
  1. [root@localhost mkspecs]# pwd  
  2. /work/program/dsk/qt-everywhere-opensource-src-4.6.1/mkspecs 

Qt库文件的实际位置:


 
 
  1. [root@localhost lib]# du -sh  
  2. 425M    .  
  3. [root@localhost lib]# pwd  
  4. /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib. 

设置完ld路径后,运行成功第一个Qt程序。。。:


现在的ld.so.conf.d下的qt配置内容如下:


 
 
  1. #/usr/lib/qt-3.3/lib // 之后需要运行ldconfig命令。  
  2. /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib 


ld设置后,基于Qt的应用启动不了。。。:


把/usr/lib/qt-3.3/lib注释掉,只配置下面的选项(运行基于qt-3.3的应用程序出错,在界面是跳出报错窗口)。


 
 
  1. /work/program/dsk/qt-everywhere-opensource-src-4.6.1/lib 

在命令行报出的错误则有些不同:


 
 
  1. [root@localhost qt]# ksnapshot  
  2. ksnapshot: error while loading shared libraries: libqt-mt.so.3: cannot open shared object file: No such file or directory 


小结:关于讲解在Linux下配置QT 学习之路的内容介绍完了希望本文对你有所帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值