X11/Linux下发布Qt程序(Deploying Qt Applications for X11/Linux)

X11/Linux下发布Qt程序(Deploying Qt Applications for X11/Linux)
2010-02-05 11:06

轉載請註明本文轉自 http://hi.baidu.com/午小夜/blog/item/b50c71502a1428848d5430aa.html

在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的方法也不錯.看看這個:

EntryDefault Value
PrefixQCoreApplication::applicationDirPath()
Documentationdoc
Headersinclude
Librarieslib
Binariesbin
Pluginsplugins
Data.
Translationstranslations
Settings.
Examples.
Demos.

最簡單的qt.conf文件這樣寫就好了:(插件在當前文件夾下的plugins文件夾裏)
[Paths]
Prefix = .
Plugins = plugins


好了.大功告成!

 

下面是解决中文乱码的问题


1. 在主程序main开始处增加以下语句,注意要按顺序书写:

 QApplication::addLibraryPath("./plugins");
 QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB2312"));
 QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));

    2.程序其他地方,包括其他文件、类文件中,直接使用中文:

QString str = "我是中文";
lbl1.setText(str);
lbl2.setText(" 你好,中文!");

    3.在部署目录(执行程序放置的目录)中建立子目录 plugins,之后在此目录中建立codecs子目录,将qcncodecs4.dll复制到此子目录中,形成如下目录结构:

<app-install-dir>/plugins/codecs

    4.大功告成!试试你的程序吧,漂亮的中文出现了!

    其实plugins中还可以放置程序中使用的其他插件,如sql和图像处理插件(到qt安装目录下的qt/plugins下按目录结构复制你所需要文件的 即可)。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值