在X11平台下发布QT程序,首先准备好程序中需要使用的资源,库和插件。比如你的可运行程序取名叫作panel,那把你的panel,那些libQt*.so.4和libQt*.so.4.6.0(链接和共享库都要)放在同一目录下(也可以不同,只要小小修改下shell文件).plugins就不多说了。在程序的同目录下,新建一个空文档,取名panel.sh (文件名与程序名同名,扩展名为sh,shell文件).
在panel.sh中原封不动的写入以下语句:#!/bin/sh
appname=`basename $0 | sed s,.sh$,,`
dirname=`dirname $0`
tmp="${dirname#?}"
if [ "${dirname%$tmp}" != "/" ]; then
dirname=$PWD/$dirname
fi
LD_LIBRARY_PATH=$dirname
export LD_LIBRARY_PATH
$dirname/$appname $*保存文件,退出.在终端给文件+x属性: 切换到程序的目录,输入
chmod +x panel.sh
然后运行shell文件就行了(确保panel程序具备X属性),它会自动更改环境变量,运行程序.
如果要调试shell文件,只需要在终端输入:
sh -x panel.sh
这样就ok了.关于plugins,有以下3种处理方法:
# Using qt.conf. This is the recommended approach since it provides the most flexibility.
# Using QApplication::addLibraryPath() or QApplication::setLibraryPaths().
# Using a third party installation utility or the target system"s package manager to change the hard-coded paths in theQtCore library.第二种方法很简单。qt.conf的方法也不错.看看这个:
| Entry | Default Value |
|---|
| Prefix | QCoreApplication::applicationDirPath() |
| Documentation | doc |
| Headers | include |
| Libraries | lib |
| Binaries | bin |
| Plugins | plugins |
| Data | . |
| Translations | translations |
| Settings | . |
| Examples | . |
| Demos | . |
最简单的qt.conf文件这样写就好了:(插件在当前文件夹下的plugins文件夹里)
[Paths]
Prefix = .
Plugins = plugins好了.大功告成!