﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-实践出真知-文章分类-QT相关资料收集</title><link>http://www.cppblog.com/lauer3912/category/15570.html</link><description>没有理由不学习</description><language>zh-cn</language><lastBuildDate>Wed, 05 Jan 2011 12:42:34 GMT</lastBuildDate><pubDate>Wed, 05 Jan 2011 12:42:34 GMT</pubDate><ttl>60</ttl><item><title>关于QString对中文的支持问题</title><link>http://www.cppblog.com/lauer3912/articles/137766.html</link><dc:creator>lauer3912</dc:creator><author>lauer3912</author><pubDate>Thu, 30 Dec 2010 14:06:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/articles/137766.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/137766.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/articles/137766.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/137766.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/137766.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: QString对中文的支持问题                                    管理提醒:&nbsp;本帖被 XChinux 执行加亮操作(2008-10-29)                                                很奇怪，我在一个工程里面是这样用QString的:QString Qstr = "D:\\你...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/articles/137766.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/137766.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">lauer3912</a> 2010-12-30 22:06 <a href="http://www.cppblog.com/lauer3912/articles/137766.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt 全局函数的使用方法</title><link>http://www.cppblog.com/lauer3912/articles/136961.html</link><dc:creator>lauer3912</dc:creator><author>lauer3912</author><pubDate>Sun, 19 Dec 2010 14:06:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/articles/136961.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/136961.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/articles/136961.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/136961.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/136961.html</trackback:ping><description><![CDATA[Qt提供了一些底层的全局函数来优化应用程序。它们大部分被使用在指定的任务当中或者应用到指定平台下。这些函数从QtCore和QtGui中输出，但是它们并不包含在一个头文件中，如果在应用程序中使用它们，就需要在调用之前声明。下面是一个例子：<br>＃ifdef Q_WS_X11<br>void qt_x11_wait_for_window_manager(QWidget *widget);<br>#endif<br><br>int main()<br>{<br>＃ifdef Q_WS_X11<br>qt_x11_wait_for_window_manager(this);<br>#endif<br>}
<img src ="http://www.cppblog.com/lauer3912/aggbug/136961.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">lauer3912</a> 2010-12-19 22:06 <a href="http://www.cppblog.com/lauer3912/articles/136961.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[编译] Qt经典出错信息之undefined reference to `vtable for classname</title><link>http://www.cppblog.com/lauer3912/articles/136425.html</link><dc:creator>lauer3912</dc:creator><author>lauer3912</author><pubDate>Tue, 14 Dec 2010 15:39:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/articles/136425.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/136425.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/articles/136425.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/136425.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/136425.html</trackback:ping><description><![CDATA[<table cellSpacing=0 cellPadding=0>
    <tbody>
        <tr>
            <td id=postmessage_428 class=t_msgfont>这个<span class=t_tag onclick=tagshow(event) href="tag.php?name=%B3%F6%B4%ED%D0%C5%CF%A2">出错信息</span>太常见了，用过Qt两个月以上的朋友基本上都能自己解决了，因为太经典了，可以给新手参考。<br><br>出错信息一般类似:undefined reference to `vtable for classname MyWidget`<br>在执行make命令后出现。<br><br>出错原因是在定义类的时候为了能使用signals和slot,在类定义的后面加了Q_OBJECT引起。 因为Q_OBJECT是一个宏，在不同的类中展开是不同的<span class=t_tag onclick=tagshow(event) href="tag.php?name=%B4%FA%C2%EB">代码</span>，例如在mywidgeth.h中生成的<br>public:<br>template inline void qt_check_for_QOBJECT_macro(const T &amp;_q_argument) const {<br>int i = qYouForgotTheQ_OBJECT_Macro(this, &amp;_q_argument); i = i;<br>}<br>static const QMetaObject staticMetaObject;<br>virtual const QMetaObject *metaObject() const;<br>virtual void *qt_metacast(const char *);<br>static inline QString tr(const char *s, const char *c = 0) { return staticMetaObject.tr(s, c); }<br>static inline QString trUtf8(const char *s, const char *c = 0) { return staticMetaObject.trUtf8(s, c); }<br>static inline QString tr(const char *s, const char *c, int n) { return staticMetaObject.tr(s, c, n); }<br>static inline QString trUtf8(const char *s, const char *c, int n) { return staticMetaObject.trUtf8(s, c, n); }<br>virtual int qt_metacall(QMetaObject::Call, int, void **); private:<br>可以看到以上的代码声明了3个从父类继承的3个虚<span class=t_tag onclick=tagshow(event) href="tag.php?name=%BA%AF%CA%FD">函数</span>。本来这三个函数的实现应该是由moc_mywidget.cpp来完成。<br>而当前的错误正是因为Makefile里没有将moc_mywidget.cpp加入<span class=t_tag onclick=tagshow(event) href="tag.php?name=%B1%E0%D2%EB">编译</span>引起。<br><br>Makefile背后的原因是qmake，因为Qt的编译<span class=t_tag onclick=tagshow(event) href="tag.php?name=%CF%B5%CD%B3">系统</span>是通过qmake将.pro文件转换成Makefile文件。当qmake扫描.h代码时发现有Q_OBJECT这样字眼的代码时，会将一个用moc生成moc_xxx.cpp代码的依赖关系写到Makefile里。如果扫描时没有找到 Q_OBJECT就不会生成额外的moc_xxx.cpp这样的文件。<br><br>出现最初一幕的原因是在执行qmake的时候.h代码里并没有O_OBJECT这样的代码。而执行make的时候.h里已经有Q_OBJECT了，解决的方法就是重新执行qmake，然后执行make.<br><br>本站所有文章由本站和原作者保留一切权力，仅在保留本版权信息、原文链接、原文作者的情况下允许转载，转载请勿删改原文内容， 并不得用于商业用途。 谢谢合作。<br>原文链接:<a href="http://www.cuteqt.com/blog/?p=116" target=_blank><u><font color=#0066cc><span class=t_tag onclick=tagshow(event) href="tag.php?name=http">http</span>://www.cuteqt.com/blog/?p=116</font></u></a></td>
        </tr>
    </tbody>
</table>
<img src ="http://www.cppblog.com/lauer3912/aggbug/136425.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">lauer3912</a> 2010-12-14 23:39 <a href="http://www.cppblog.com/lauer3912/articles/136425.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[编译] QT编译./configure参数的详细解释［新手充电必读］</title><link>http://www.cppblog.com/lauer3912/articles/136423.html</link><dc:creator>lauer3912</dc:creator><author>lauer3912</author><pubDate>Tue, 14 Dec 2010 15:36:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/articles/136423.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/136423.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/articles/136423.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/136423.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/136423.html</trackback:ping><description><![CDATA[<font color=#ff8c00>可以随便的转载，只要按照规矩走带上咱论坛的链接就好。<img border=0 alt="" src="http://www.cuteqt.com/bbs/images/smilies/default/smile.gif" smilieid="1"><br><br></font>==================================<br>====<font color=red>全文是按照./configure -help来翻译的</font>========<br>==================================<br><font size=2>Usage:&nbsp;&nbsp;configure </font><font size=2><font color=blue>[-h] [-prefix &lt;dir&gt;] [-prefix-install] [-bindir &lt;dir&gt;] [-libdir &lt;dir&gt;]</font></font><font size=2><br></font><font size=2><font color=blue>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-docdir &lt;dir&gt;] [-headerdir &lt;dir&gt;] [-plugindir &lt;dir&gt; ] [-datadir &lt;dir&gt;]</font></font><font size=2><br></font><font size=2><font color=blue>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-translationdir &lt;dir&gt;] [-sysconfdir &lt;dir&gt;] [-<span class=t_tag onclick=tagshow(event) href="tag.php?name=example">example</span>sdir &lt;dir&gt;]</font></font><font size=2><br></font><font size=2><font color=blue>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-demosdir &lt;dir&gt;] [-buildkey &lt;key&gt;]</font></font><font size=2><br></font><font size=2><font color=red><strong>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;这些是基本参数</strong></font></font><font size=2><br></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-release] [-debug][-debug-and-release] [-developer-build]</font></font><font size=2><br></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-shared] [-static] [-no-fast] [-fast] [-no-largefile]</font></font><font size=2><br></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-largefile] [-no-exceptions] [-exceptions] [-no-accessibility]</font></font><font size=2><br></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-accessibility] [-no-stl] [-stl] [-no-sql-&lt;driver&gt;] [-sql-&lt;driver&gt;]</font></font><font size=2><br></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-plugin-sql-&lt;driver&gt;] [-system-sqlite] [-no-qt3support] [-qt3support]</font></font><font size=2><br></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-platform] [-D &lt;string&gt;] [-I &lt;string&gt;] [-L &lt;string&gt;] [-help]</font></font><font size=2><br></font><font size=2><font color=red><strong>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;这些是对QT所支持模块等设置的参数</strong></font></font><font size=2><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</font><font size=2><font color=blue>[-qt-zlib] [-system-zlib] [-no-gif] [-qt-gif] [-no-libtiff] [-qt-libtiff] [-system-libtiff]</font></font><font size=2><br></font><font size=2><font color=blue>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-no-libpng] [-qt-libpng] [-system-libpng] [-no-libmng] [-qt-libmng]</font></font><font size=2><br></font><font size=2><font color=blue>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-system-libmng] [-no-libjpeg] [-qt-libjpeg] [-system-libjpeg] [-make &lt;part&gt;]</font></font><font size=2><br></font><font size=2><font color=blue>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-no-make &lt;part&gt;] [-R &lt;string&gt;]&nbsp;&nbsp;[-l &lt;string&gt;] [-no-rpath]&nbsp;&nbsp;[-rpath] [-continue]</font></font><font size=2><br></font><font size=2><font color=blue>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-verbose] [-v] [-silent] [-no-nis] [-nis] [-no-cups] [-cups] [-no-iconv]</font></font><font size=2><br></font><font size=2><font color=blue>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-iconv] [-no-pch] [-pch] [-no-dbus] [-dbus] [-dbus-linked]</font></font><font size=2><br></font><font size=2><font color=blue>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-no-separate-debug-info]</font></font><font size=2><br></font><font size=2><font color=red><strong>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;这些是第三方库的支持参数</strong></font></font><font size=2><br></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-no-mmx] [-no-3dnow] [-no-sse] [-no-sse2]</font></font><font size=2><br></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-qtnamespace &lt;namespace&gt;] [-qtlibinfix &lt;infix&gt;] [-separate-debug-info] <br></font></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</font></font><font size=2><font color=navy>[-armfpa]</font></font><font size=2><font color=navy>[-no-optimized-qmake] [-optimized-qmake] [-no-xmlpatterns]<br></font></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</font></font><font size=2><font color=navy>[-xmlpatterns]</font></font><font size=2><font color=navy>[-no-phonon] [-phonon] [-no-phonon-backend] <br></font></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</font></font><font size=2><font color=navy>[-phonon-backend]</font></font><font size=2><font color=navy>[-no-openssl] [-openssl] [-openssl-linked]</font></font><font size=2><br></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-no-gtkstyle] [-gtkstyle] [-no-svg] [-svg] [-no-webkit] [-webkit]</font></font><font size=2><br></font><font size=2><font color=navy>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[-no-scripttools] [-scripttools]</font></font><font size=2><br><br><strong><font size=4>安装选项：<br><br></font></strong><font color=blue>以下选项都是可选，通过他们指定安装目录，不指定则用默认目录。选项前标记*的则为系统默认，+则为添加才有效那种</font><br><strong>&nbsp; &nbsp; -prefix &lt;dir&gt; ......... 指定安装目录默认在 /usr/local/Trolltech/QtEmbedded-4.X.X</strong><br><strong>&nbsp; &nbsp; -hostprefix [dir] ..... 指定可扩展的工具库安装路径，默认当前目录</strong><br><strong>&nbsp;&nbsp;* -prefix-install ........ 指定QT的本地安装. 至</strong><br><strong>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;/usr/local/Trolltech/QtEmbedded-4.X.X, 此选项优先于-PREFIX.</strong><br><br><font color=blue>以下选项用来指定分开安装不同部分，比如希望将可执行的放在/usr/bin 将库文件放在/lib下等等:</font><br><br><strong>&nbsp; &nbsp; -bindir &lt;dir&gt; ......... 指定可执行文件路径 &lt;dir&gt;(默认 PREFIX/bin下)</strong><br><strong>&nbsp; &nbsp; -libdir &lt;dir&gt; .......... 指定库文件路径 &lt;dir&gt;(默认 PREFIX/lib)</strong><br><strong>&nbsp; &nbsp; -docdir &lt;dir&gt; ........ 指定文档路径 &lt;dir&gt;(默认 PREFIX/doc)</strong><br><strong>&nbsp; &nbsp; -headerdir &lt;dir&gt; .... 指定头文件路径 &lt;dir&gt;(默认 PREFIX/include)</strong><br><strong>&nbsp; &nbsp; -plugindir &lt;dir&gt; ...... 指定插件路径 &lt;dir&gt; (默认 PREFIX/plugins)</strong><br><strong>&nbsp; &nbsp; -datadir &lt;dir&gt; ........ 指定QT要使用到的一些数据文件所在路径 &lt;dir&gt; (默认 PREFIX)</strong><br><strong>&nbsp; &nbsp; -translationdir &lt;dir&gt; . 指定QT程序的翻译文件路径 &lt;dir&gt;(默认 PREFIX/translations)</strong><br><strong>&nbsp; &nbsp; -sysconfdir &lt;dir&gt; ..... 指定QT的设置文件路径 &lt;dir&gt;(默认 PREFIX/etc/settings)</strong><br><strong>&nbsp; &nbsp; -examplesdir &lt;dir&gt; .... 指定实例文件， &lt;dir&gt;(默认 PREFIX/examples)</strong><br><strong>&nbsp; &nbsp; -demosdir &lt;dir&gt; ....... 指定demos的安装路径 &lt;dir&gt; (默认 PREFIX/demos)</strong><br><br><font color=blue>可以用这些选项去匹配自己所想要的插件</font><br><br><strong>&nbsp; &nbsp; - buildkey &lt;key&gt; ...... 通过指定的key生成QT库和插件。</strong><br><strong><font size=4>配置选项:<br><br></font></strong><font color=blue>默认的选项(*),可选添加选项(+)</font><br><br><br><font color=black>*&nbsp;&nbsp;-release ........... </font><font size=2><font color=black>此选项在编译过程QT会对程序进行优化，在发布软件的时候应该用此选项</font></font><font size=2><font color=black>，是默认选项</font></font><br><font size=2><font color=black>&nbsp; &nbsp; -debug ............. </font></font><font size=2><font color=black>加上此选项编译程序QT不会做出优化，往往在开发过程使用此选项</font></font><font size=2><br><font color=black>&nbsp; &nbsp; -debug-and-release . 编译两个版本</font><br><br><font color=black>&nbsp; &nbsp; -developer-build.... 编译Qt的开发商和连接选项（包括自动测试出口的Qt） </font><br><br><font color=black>&nbsp; &nbsp; -opensource......... 以开源版本发布程序</font><br><font color=black>&nbsp; &nbsp; -commercial......... 以商业版本发布程序</font><br><br><font color=black>*&nbsp;&nbsp;-shared ............ 创建和使用共享Qt库。</font><br><font color=black>&nbsp; &nbsp; -static ............ 创建和使用静态的Qt库。</font><br><br><font color=black>*&nbsp;&nbsp;-no-fast ........... 使用通常的Makefile来编译，是默认选项</font><br><font color=black>&nbsp; &nbsp; -fast .............. 快速编译，除了封装必要的库，部分步骤省略或者用快速的方法处理</font><br><font color=black>&nbsp; &nbsp; -no-largefile ...... 禁用大文件支持。</font><br><font color=black>+&nbsp;&nbsp;-largefile ......... 支持访问大于4GB的文件</font><br><font color=black>*&nbsp;&nbsp;-no-exceptions ..... 禁用编译器本身对异常的处理</font><br><font color=black>&nbsp; &nbsp; -exceptions ........ 启用编译器本身对异常的处理</font><br><font color=black>&nbsp; &nbsp; -no-accessibility .. </font><br><font color=black>*&nbsp;&nbsp;-accessibility .....&nbsp; &nbsp;禁用/启用无障碍支持</font><br><font color=black>&nbsp; &nbsp; -no-stl ............ </font><br><font color=black>*&nbsp;&nbsp;-stl ...............&nbsp; &nbsp;禁用/启用STL支持</font><br><font color=black>&nbsp; &nbsp; -no-sql-&lt;driver&gt; ... 禁用SQL</font><br><font color=black>&nbsp; &nbsp; -qt-sql-&lt;driver&gt; ... 根据需求启用SQL插件（默认全部关闭）</font><br><font color=black>&nbsp; &nbsp; -plugin-sql-&lt;driver&gt; 禁用/启用/启用插件 对SQL的支持</font><br><br><font color=black>&nbsp; &nbsp; -system-sqlite ..... 启用支持sqlite也可用-qt-sqlite</font><br><br><font color=black>&nbsp; &nbsp; -no-qt3support ..... </font><br><font color=black>*&nbsp;&nbsp;-qt3support ........ 禁用/启用qt3支持模块</font><br><br><font color=black>&nbsp; &nbsp; -no-xmlpatterns .... </font><br><font color=black>+&nbsp;&nbsp;-xmlpatterns ....... 禁用/启用xmlpatterns模块</font><br><br><font color=black>&nbsp; &nbsp; -no-phonon ......... </font><br><font color=black>+&nbsp;&nbsp;-phonon ............ 禁用/启用Phonon模块（可以理解为声音控制模块）</font><br><br><br><font color=black>&nbsp; &nbsp; -no-phonon-backend.. </font><br><font color=black>+&nbsp;&nbsp;-phonon-backend..... 禁用/启用phonon-backend模块</font><br><font color=black>&nbsp; &nbsp; -no-svg ............ </font><br><font color=black>+&nbsp;&nbsp;-svg ............... 禁用/启用svg模块</font><br><br><font color=black>&nbsp; &nbsp; -no-webkit ......... </font><br><font color=black>+&nbsp;&nbsp;-webkit ............ 禁用/启用webkit模块（访问网络模块）</font><br><font color=black>&nbsp; &nbsp; -no-scripttools .... </font><br><font color=black>+&nbsp;&nbsp;-scripttools ....... 禁用/启用scripttools模块</font><br><br><font color=black>&nbsp; &nbsp; -platform target ... x86平台指定模块 (qws/linux-x86-g++).</font><br><br><br><font color=black>&nbsp; &nbsp; -no-mmx ............ 我不知道这四个是什么，貌似是几个指令系统？</font><br><font color=black>&nbsp; &nbsp; -no-3dnow .......... </font><br><font color=black>&nbsp; &nbsp; -no-sse ............ </font><br><font color=black>&nbsp; &nbsp; -no-sse2 ........... </font><br><br><font color=black>&nbsp; &nbsp; -qtnamespace &lt;name&gt;&nbsp;&nbsp;指定所有库代码路径.</font><br><font color=black>&nbsp; &nbsp; -qtlibinfix &lt;infix&gt;&nbsp;&nbsp;重命名所有.so库文件到指定路径</font><br><br><font color=black>&nbsp; &nbsp; -D &lt;string&gt; ........ 添加一个预处理器</font><br><font color=black>&nbsp; &nbsp; -I &lt;string&gt; ........ 添加一个明确的头文件路径</font><br><font color=black>&nbsp; &nbsp; -L &lt;string&gt; ........ 添加一个明确的库文件路径</font><br><br><font color=black>&nbsp; &nbsp; -help, -h .......... 显示帮助信息</font><br><strong><font size=4>第三方库选项:<br></font></strong><font color=blue>（以下是第三方库，往往编译过程中需要依赖的都要加上，也没什么好说的，缺什么就加什么）</font><br><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-qt-zlib ........... </font><br><font color=black>+&nbsp;&nbsp;-system-zlib .......&nbsp; &nbsp;&nbsp; &nbsp;zlib依赖包 详询 <a href="http://www.gzip.org/zlib" target=_blank><u><font color=#0066cc>http://www.gzip.org/zlib</font></u></a></font><br><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-no-gif ............ </font><br><font color=black>*&nbsp;&nbsp;-qt-gif ............&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;gif图片支持包</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;See also src/plugins/imageformats/gif/qgifhandler.h</font><br><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-no-libtiff ........ </font><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-qt-libtiff ........&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;tiff支持插件</font><br><font color=black>+&nbsp;&nbsp;-system-libtiff ....&nbsp; &nbsp;&nbsp;&nbsp;默认是-system调用系统的，出错的话可以尝试用-qt，qt的在编译过程不容易出错</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 详询 <a href="http://www.libtiff.org/" target=_blank><u><font color=#0066cc>http://www.libtiff.org</font></u></a></font><br><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-no-libpng ......... </font><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-qt-libpng .........&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;png图片支持插件</font><br><font color=black>+&nbsp;&nbsp;-system-libpng ..... </font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;详询 <a href="http://www.libpng.org/pub/png" target=_blank><u><font color=#0066cc>http://www.libpng.org/pub/png</font></u></a></font><br><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-no-libmng ......... </font><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-qt-libmng .........&nbsp; &nbsp;&nbsp; &nbsp; mng支持插件</font><br><font color=black>+&nbsp;&nbsp;-system-libmng ..... </font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;详询 <a href="http://www.libmng.com/" target=_blank><u><font color=#0066cc>http://www.libmng.com</font></u></a></font><br><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-no-libjpeg ........ </font><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-qt-libjpeg ........&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;jpeg图片支持插件</font><br><font color=black>+&nbsp;&nbsp;-system-libjpeg .... </font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 详询 <a href="http://www.ijg.org/" target=_blank><u><font color=#0066cc>http://www.ijg.org</font></u></a></font><br><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-no-openssl ........ </font><br><font color=black>+&nbsp;&nbsp;-openssl ...........&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;openssl支持插件</font><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-openssl-linked .... </font><br><br><font color=black>&nbsp; &nbsp;&nbsp;&nbsp;-ptmalloc ..........&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;系统内存分配器</font><br><strong><font size=4>其他选项：<br></font></strong><font color=blue>(扩展选项，模块的选择等，使编译更加人性化</font>)<br>&nbsp; &nbsp; <font color=black>-make &lt;part&gt; .......&nbsp; &nbsp; 选择是否编译某些无关紧要的子模块</font><br><font color=black>&nbsp; &nbsp; -nomake &lt;part&gt; ..... （例如不想编译系统自导的demos则可使用-nomake demos）</font><br><font color=black>&nbsp; &nbsp; -R &lt;string&gt; ........&nbsp; &nbsp;&nbsp; &nbsp;添加一个动态库</font><br><font color=black>&nbsp; &nbsp; -l &lt;string&gt; ........&nbsp; &nbsp;&nbsp; &nbsp; 添加一个静态库</font><br><font color=black>&nbsp; &nbsp; -no-rpath .......... </font><br><font color=black>+&nbsp;&nbsp;-rpath .............&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;是否将生成的库安装在软件的安装目录，默认是在安装目录，否则自己指定路径</font><br><br><font color=black>&nbsp; &nbsp; -continue ..........&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;忽略错误一路前奔的编译，因为一般情况是按照模块逐个编译的，</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 碰到错误就停止。加上此参数是全部编译最后处理</font><br><font color=black>&nbsp; &nbsp; -verbose, -v .......&nbsp; &nbsp;&nbsp; &nbsp;显示每个步骤的详细信息</font><br><font color=black>&nbsp; &nbsp; -silent ............&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;安静的编译省略信息回显</font><br><br><font color=black>*&nbsp;&nbsp;-no-optimized-qmake ... </font><br><font color=black>&nbsp; &nbsp; -optimized-qmake ......&nbsp;&nbsp;禁用/开启qmake的优化作用</font><br><br><font color=black>&nbsp; &nbsp; -no-nis ............ </font><br><font color=black>*&nbsp;&nbsp;-nis ...............&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;禁用/开启NIS的支持</font><br><br><font color=black>&nbsp; &nbsp; -no-cups ........... </font><br><font color=black>*&nbsp;&nbsp;-cups ..............&nbsp; &nbsp;&nbsp; &nbsp; 禁用/开启对CUPS的支持</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;需要 cups/cups.h and libcups.so.2.</font><br><br><font color=black>&nbsp; &nbsp; -no-iconv .......... </font><br><font color=black>*&nbsp;&nbsp;-iconv .............&nbsp; &nbsp;&nbsp; &nbsp;禁用/开启对iconv的支持.</font><br><br><font color=black>&nbsp; &nbsp; -no-pch ............ </font><br><font color=black>*&nbsp;&nbsp;-pch ...............&nbsp; &nbsp;&nbsp; &nbsp;禁用/开启是否使用预处理器头文件</font><br><br><font color=black>&nbsp; &nbsp; -no-dbus ........... </font><br><font color=black>+&nbsp;&nbsp;-dbus ..............&nbsp; &nbsp;&nbsp;&nbsp;禁用/开启对QTdbus模块的编译</font><br><font color=black>&nbsp; &nbsp; -dbus-linked ....... </font><br><br><font color=black>&nbsp; &nbsp; -reduce-relocations ..... 减少因为链接优化而导致的而外的库文件重置</font><br><br><font color=black>&nbsp; &nbsp; -no-separate-debug-info . 不将调试信息放在一个文件内</font><br><font color=black>*&nbsp;&nbsp;-separate-debug-info .... 将调试信息放在一个文件内</font><br><br><strong><font size=4>以下参数仅限于嵌入式QTE编译使用：<br><br></font></strong>&nbsp; &nbsp; <font color=black>-xplatform target ...&nbsp; &nbsp;&nbsp; &nbsp;交叉编译过程指定目标平台</font><br><font color=black>&nbsp; &nbsp; -no-feature-&lt;feature&gt;&nbsp; &nbsp;不编译&lt;feature&gt;.</font><br><font color=black>&nbsp; &nbsp; -feature-&lt;feature&gt; ..&nbsp; &nbsp; 编译&lt;feature&gt;. 可选feature在src/corelib/global/qfeatures.txt文件内可查寻</font><br><br><font color=black>&nbsp; &nbsp; -embedded &lt;arch&gt; ....&nbsp; &nbsp;指定嵌入式平台的类型例如：arm mips x86 generic</font><br><br><font color=black>&nbsp; &nbsp; -armfpa ............. </font><br><font color=black>&nbsp; &nbsp; -no-armfpa ..........&nbsp; &nbsp;&nbsp; &nbsp; 禁用/启用armfpa浮点格式支持</font><br><br><font color=black>&nbsp; &nbsp; -little-endian ......&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;指定字节顺序为小字节序、低字节序</font><br><font color=black>&nbsp; &nbsp; -big-endian .........&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;指定字节顺序为大字节序、高字节序</font><br><br><font color=black>&nbsp; &nbsp; -host-little-endian .&nbsp; &nbsp;&nbsp; &nbsp; 指定主机平台字节顺序为小字节序、低字节序</font><br><font color=black>&nbsp; &nbsp; -host-big-endian ....&nbsp; &nbsp;&nbsp;&nbsp;指定主机平台字节顺序为大字节序、高字节序</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;注：只需指定目标平台的字节顺序，否则将会选用主机的字节顺序</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;arm的编译过程这项得加</font><br><br><br><font color=black>&nbsp; &nbsp; -no-freetype ........ </font><br><font color=black>&nbsp; &nbsp; -qt-freetype ........&nbsp; &nbsp;&nbsp; &nbsp;禁用/启用对freetype 模块的支持</font><br><font color=black>*&nbsp;&nbsp;-system-freetype .... </font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;详询 <a href="http://www.freetype.org/" target=_blank><u><font color=#0066cc>http://www.freetype.org/</font></u></a></font><br><br><font color=black>&nbsp; &nbsp; -qconfig local ......&nbsp; &nbsp;&nbsp; &nbsp;在不指定此配置的情况下系统使用</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;src/corelib/global/qconfig-local.h </font><br><br><font color=black>&nbsp; &nbsp; -depths &lt;list&gt; ......&nbsp; &nbsp;&nbsp;&nbsp;支持显示设备的位深度。有1, 4, 8, 12, 15, 16, 18, 24, 32 and 'all'.</font><br><br><font color=black>&nbsp; &nbsp; -qt-decoration-&lt;style&gt; ....指定编译后的界面风格默认是windows</font><br><br><br><font color=black>&nbsp; &nbsp; -plugin-decoration-&lt;style&gt; 指定插件风格默认windows</font><br><font color=black>&nbsp; &nbsp; -no-decoration-&lt;style&gt; ....不知定风格采用默认选项</font><br><br><font color=black>&nbsp; &nbsp; -no-opengl .......... </font><br><font color=black>&nbsp; &nbsp; -opengl &lt;api&gt; .......&nbsp; &nbsp;&nbsp; &nbsp;禁用/开启对opengl的支持</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;不指定型号则系统会自动检测</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 注意：使用此选项的前提条件是硬件支持且可以驱动</font><br><br><font color=black>&nbsp; &nbsp; -qt-gfx-&lt;driver&gt; ...&nbsp; &nbsp;&nbsp; &nbsp;指定显示设备驱动库</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;参考选项为：[ linuxfb transformed qvfb vnc multiscreen ]</font><br><font color=black>&nbsp; &nbsp; -plugin-gfx-&lt;driver&gt; 指定显示插件驱动库</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;参考选项为：[&nbsp;&nbsp;ahi directfb hybrid linuxfb powervr qvfb transformed vnc ]</font><br><font color=black>&nbsp; &nbsp; -no-gfx-&lt;driver&gt; ... 不加载显示设备</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 参考选项为: [ linuxfb transformed qvfb vnc multiscreen ]</font><br><br><font color=black>&nbsp; &nbsp; -qt-kbd-&lt;driver&gt; ... 指定图形界面下的键盘驱动库</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;参考选项为: [ tty usb sl5000 yopy vr41xx qvfb ]</font><br><br><font color=black>&nbsp; &nbsp; -plugin-kbd-&lt;driver&gt; E指定图形界面下键盘插件驱动库</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 参考选项为: [&nbsp;&nbsp;linuxis sl5000 usb vr41xx yopy ]</font><br><br><font color=black>&nbsp; &nbsp; -no-kbd-&lt;driver&gt; ... 不加载指定驱动</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 参考选项为: [ tty usb sl5000 yopy vr41xx qvfb ]</font><br><br><font color=black>&nbsp; &nbsp; -qt-mouse-&lt;driver&gt; ... 指定图形界面下鼠标驱动库</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;参考选项为: [ pc bus linuxtp yopy vr41xx tslib(触摸屏选这个) qvfb ]</font><br><font color=black>&nbsp; &nbsp; -plugin-mouse-&lt;driver&gt; 鼠标插件驱动库</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;参考选项为: [&nbsp;&nbsp;bus linuxis linuxtp pc tslib vr41xx yopy ]</font><br><font color=black>&nbsp; &nbsp; -no-mouse-&lt;driver&gt; ... 指定不加载的鼠标驱动库模块</font><br><font color=black>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;参考选项为: [ pc bus linuxtp yopy vr41xx tslib qvfb ]</font><br><br><font color=black>&nbsp; &nbsp; -iwmmxt ............ 编译使用iwmmxt指令集，方便对某些XScale CPUs的支持</font><br><br><font color=black>&nbsp; &nbsp; -no-glib ........... </font><br><font color=black>+&nbsp;&nbsp;-glib .............. 禁用/启用对glib的支持</font><br><br></font></font>
<img src ="http://www.cppblog.com/lauer3912/aggbug/136423.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">lauer3912</a> 2010-12-14 23:36 <a href="http://www.cppblog.com/lauer3912/articles/136423.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt 中文显示</title><link>http://www.cppblog.com/lauer3912/articles/136247.html</link><dc:creator>lauer3912</dc:creator><author>lauer3912</author><pubDate>Sun, 12 Dec 2010 16:13:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/articles/136247.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/136247.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/articles/136247.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/136247.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/136247.html</trackback:ping><description><![CDATA[<p>&nbsp;</p>
<table cellSpacing=0 cellPadding=0>
    <tbody>
        <tr>
            <td id=postmessage_300948 class=t_msgfont>QT默认的编码（unicode）是不能显示<span class=t_tag onclick=tagshow(event) href="tag.php?name=%D6%D0%CE%C4">中文</span>的，可能由于<span class=t_tag onclick=tagshow(event) href="tag.php?name=windows">windows</span>的默认编码的问题，windows默认使用（GBK/GB2312/GB18030），所以需要来更改QT<span class=t_tag onclick=tagshow(event) href="tag.php?name=%B3%CC%D0%F2">程序</span>的编码来<span class=t_tag onclick=tagshow(event) href="tag.php?name=%BD%E2%BE%F6">解决</span>中文显示的问题。<br><br>QT中有专门的一个类来处理编码的问题(QTextCodec)。<br><br>在QT3中，QApplication可以<span class=t_tag onclick=tagshow(event) href="tag.php?name=%C9%E8%D6%C3">设置</span>程序的默认编码，但是在QT4中已经没有了该成员<span class=t_tag onclick=tagshow(event) href="tag.php?name=%BA%AF%CA%FD">函数</span>。<br>可以以下的这些方法来设置编码。<br><br><br><br><br>1. 设置QObject的成员函数tr()的编码。<br><br>QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));<br><br>其中的codecForName函数是根据参数中的编码名称，在<span class=t_tag onclick=tagshow(event) href="tag.php?name=%CF%B5%CD%B3">系统</span>已经安装的编码方案中需找最佳的匹配编码类型，该查找是大小写不敏感的。如果没有找到，就返回0。<br><br>具体的转换<span class=t_tag onclick=tagshow(event) href="tag.php?name=%B4%FA%C2%EB">代码</span>看下面：<br>#include &lt;QApplication&gt;<br>#include &lt;QTextCodec&gt;<br>#include &lt;QLabel&gt;<br><br><br>int main(int argc,char *argv[])<br>{<br>QApplication app(argc,argv);<br>QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));<br>QLabel hello(QObject::tr("你好世界"));<br>hello.setWindowTitle(QObject::tr("Qt中文显示"));<br>hello.show();<br>return app.exec();<br>}<br><br>注意：<br>setCodecForTr一定要在QApplication后面。不然没有<span class=t_tag onclick=tagshow(event) href="tag.php?name=%D0%A7%B9%FB">效果</span>。而且这种方法只会转换经过tr函数的<span class=t_tag onclick=tagshow(event) href="tag.php?name=%D7%D6%B7%FB">字符</span>串，并不转换不经过tr函数的字符串。<br><br>技巧：<br>可以用codecForLocale函数来返回现在系统的默认编码，这样更容易做多编码的程序而不用自己手动来更改具体的编码。<br><br><br>2. 使用QString的fromLocal8Bit()函数<br><br>这个方法是最快的，系统直接<span class=t_tag onclick=tagshow(event) href="tag.php?name=%D7%D4%B6%AF">自动</span>将char *的参数转换成为系统默认的编码，然后返回一个QString。<br><br>#include &lt;QApplication&gt;<br>#include &lt;QTextCodec&gt;<br>#include &lt;QLabel&gt;<br><br><br>int main(int argc,char *argv[])<br>{<br><br>&nbsp; &nbsp;QApplication app(argc,argv);<br><br>&nbsp; &nbsp;QString str;<br>str = str.fromLocal8Bit("Qt中文显示");<br>hello.setWindowTitle(str);<br>hello.show();<br>return app.exec();<br>}<br><br>3. 用QTextCodec的toUnicode方法来显示中文<br><br>#include &lt;QApplication&gt;<br>#include &lt;QTextCodec&gt;<br>#include &lt;QLabel&gt;<br><br><br>int main(int argc,char *argv[])<br>{<br><br>&nbsp; &nbsp;QApplication app(argc,argv);<br>QLabel hello(QObject::tr("你好世界").toLocal8Bit());<br>QTextCodec *codec = QTextCodec::codecForLocale();<br>QString a = codec-&gt;toUnicode("Qt中文显示");<br>hello.setWindowTitle(a);<br>hello.show();<br>return app.exec();<br>}<br><br><br><br>PS:关于中文显示乱码的问题我纠结了好久，在网上查的一些方法似乎都不是太管用，所用我自己又实验了很多次，终于解决了这个问题。我其他两种方法我没有试过，我只说第一种方法：<br><br>&nbsp; &nbsp; 刚开始的时候我设置QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));或者将"GBK"换成"GB2312","GB18030"都没有成功，依然是乱码。不过也并不是一定不行，后来发现有些时候这样设置也是可以的，我认为可能与源代码的编码方式有关。我后来又找到了一种解决办法就是设置成QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));或者设置成QTextCodec::setCodecForTr(QTextCodec::codecForLocale());我在Ubuntu下，这两种设置都可行；在Windows下，QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));和QTextCodec::setCodecForTr(QTextCodec::codecForLocale());中应该有一种可以，希望我的这些研究能够帮到你</td>
        </tr>
    </tbody>
</table>
<img src ="http://www.cppblog.com/lauer3912/aggbug/136247.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">lauer3912</a> 2010-12-13 00:13 <a href="http://www.cppblog.com/lauer3912/articles/136247.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QToolTip 的使用</title><link>http://www.cppblog.com/lauer3912/articles/135747.html</link><dc:creator>lauer3912</dc:creator><author>lauer3912</author><pubDate>Tue, 07 Dec 2010 14:50:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/articles/135747.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/135747.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/articles/135747.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/135747.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/135747.html</trackback:ping><description><![CDATA[最简单和常规的用法<br>QWidget::setToolTip()<br>高级用法，使用类型的 QEvent::ToolTip 的 QHelpEvent 事件（注意ignore使用）<br>bool SortingBox::event(QEvent *event) <br>{ <br>&nbsp;&nbsp;&nbsp; if (event-&gt;type() == QEvent::ToolTip) { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QHelpEvent *helpEvent = static_cast&lt;QHelpEvent *&gt;(event); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (xxxxxx) { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QToolTip::showText(helpEvent-&gt;globalPos(), "xxxxxxxxx"); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QToolTip::hideText(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; event-&gt;ignore(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true; <br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;return QWidget::event(event); <br>}<br>立即显示 tooltip，就像上面用的，直接调用 showText()
<img src ="http://www.cppblog.com/lauer3912/aggbug/135747.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">lauer3912</a> 2010-12-07 22:50 <a href="http://www.cppblog.com/lauer3912/articles/135747.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt坐标系统与图形绘制</title><link>http://www.cppblog.com/lauer3912/articles/135627.html</link><dc:creator>lauer3912</dc:creator><author>lauer3912</author><pubDate>Mon, 06 Dec 2010 14:41:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/articles/135627.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/135627.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/articles/135627.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/135627.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/135627.html</trackback:ping><description><![CDATA[<p class=grey><span class=STYLE2><strong>作者：</strong>穆煜，<a href="http://www.embedu.org/" target=_blank><font color=#000000>华清远见嵌入式学院</font></a>讲师。</span></p>
<p class=grey>为了能够使用Qt开发图形绘制软件，首先应该掌握Qt的坐标系统。在Qt中，通过QPainter类来控制它的坐标系统。连同QPaintDevice类与QPaintEngine类，QPainter类构成了Qt绘图系统的基础。其中，QPainter用于执行绘图的操作；QPaintDevice是对一块二维空间的抽象，在这块空间上，我们可以使用QPainter进行图形的绘制；QPaintEngine提供了在不同的设备上进行绘图的接口。</p>
<p class=grey>QPaintDevice类是能够进行绘图的对象的基类，QWidget，QPixmap，QPicture，QImage，以及QPrinter类继承了QPaintEngine类的绘图能力。绘图设备的缺省坐标系统是以左上角作为原点，x坐标向右递增，y坐标向下递增。单位对于不同的设备是不同的，在基于像素的设备上，以一个像素作为缺省单位，而在打印机上，以1/72英寸作为缺省单位。</p>
<p class=grey>在编写图形绘制软件时，我们需要进行逻辑坐标与物理坐标之间的转换，这部分功能由QPainter的转换矩阵，视口，以及窗口来实现。缺省情况下，逻辑坐标与物理坐标是一致的。QPainter也支持平移与旋转这样的坐标变换。</p>
<p class=grey>图元的尺寸（宽度与高度）总是对应于它的数学模型，并且会忽略它所使用的笔的宽度。下图是通过两个点来实现矩形和直线的例子，用到的代码为：</p>
<p class=grey>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QRect（1，2，7，6） &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QLine（2，7，6，1）</p>
<p class=grey><img style="CURSOR: pointer" onclick=javascript:window.open(this.src); alt=图片点击可在新窗口打开查看 src="http://www.embedu.org/Column/images/Column76-1.jpg" width=234 onload=imgresize(this); height=242> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img style="CURSOR: pointer" onclick=javascript:window.open(this.src); alt=图片点击可在新窗口打开查看 src="http://www.embedu.org/Column/images/Column76-2.jpg" width=235 onload=imgresize(this); height=242></p>
<p class=grey>在绘图的时候，我们使用QPainter::Antialiasing的渲染暗示来控制像素渲染。计算机绘图会出现走样的情况，如下图所示：在绘制直线的时候，出现了边缘不规则的情况。</p>
<p class=grey><img style="CURSOR: pointer" onclick=javascript:window.open(this.src); alt=图片点击可在新窗口打开查看 src="http://www.embedu.org/Column/images/Column76-3.jpg" width=235 onload=imgresize(this); height=242> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img style="CURSOR: pointer" onclick=javascript:window.open(this.src); alt=图片点击可在新窗口打开查看 src="http://www.embedu.org/Column/images/Column76-4.jpg" width=235 onload=imgresize(this); height=242></p>
<p class=grey>如果我们设置了QPainter的反走样渲染暗示，像素将会对称的出现在点的两侧。因此，可以使用以下代码来解决绘制直线出现锯齿的问题：</p>
<p class=grey>这样绘制的直线如下图所示：</p>
<p class=grey><img style="CURSOR: pointer" onclick=javascript:window.open(this.src); alt=图片点击可在新窗口打开查看 src="http://www.embedu.org/Column/images/Column76-5.jpg" width=235 onload=imgresize(this); height=242></p>
<img src ="http://www.cppblog.com/lauer3912/aggbug/135627.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">lauer3912</a> 2010-12-06 22:41 <a href="http://www.cppblog.com/lauer3912/articles/135627.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>收集转载 字符编码笔记：ASCII，Unicode和UTF-8</title><link>http://www.cppblog.com/lauer3912/articles/135312.html</link><dc:creator>lauer3912</dc:creator><author>lauer3912</author><pubDate>Thu, 02 Dec 2010 15:30:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/articles/135312.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/135312.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/articles/135312.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/135312.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/135312.html</trackback:ping><description><![CDATA[<p>&nbsp;</p>
<span style="TEXT-ALIGN: left; WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Simsun; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(17,17,17); WORD-SPACING: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class=Apple-style-span><span style="LINE-HEIGHT: 21px; FONT-FAMILY: Georgia, serif; FONT-SIZE: 12px; WORD-SPACING: 2px" class=Apple-style-span>
<div style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" class=asset-header>
<h1 style="BORDER-BOTTOM: rgb(211,211,211) 1px solid; TEXT-ALIGN: left; PADDING-BOTTOM: 0.2em; LINE-HEIGHT: 72px; BORDER-RIGHT-STYLE: none; TEXT-TRANSFORM: capitalize; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0.4em 0px 0.2em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; LETTER-SPACING: -0.03em; COLOR: rgb(0,0,0); FONT-SIZE: 2.88em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: 900; TEXT-DECORATION: none; PADDING-TOP: 0px" id=page-title class="asset-name entry-title">字符编码笔记：ASCII，Unicode和UTF-8</h1>
<div style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 0.8; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1.5em auto 2em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" class=asset-meta>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(85,102,119); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" class="vcard author">作者：<span class=Apple-converted-space>&nbsp;</span><a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(85,102,119); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" class="fn url" href="http://www.ruanyifeng.com/">阮一峰</a></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(85,102,119); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">日期：<span class=Apple-converted-space>&nbsp;</span><a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(85,102,119); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" href="http://www.ruanyifeng.com/blog/2007/10/"><abbr style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(85,102,119); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" class=published title=2007-10-28T22:29:57+08:00>2007年10月28日</abbr></a></p>
</div>
</div>
<div style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" id=main-content class="asset-content entry-content">
<div style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" class=asset-body>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">今天中午，我突然想搞清楚Unicode和UTF-8之间的关系，于是就开始在网上查资料。</p>
</div>
<div style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" id=more class=asset-more>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">结果，这个问题比我想象的复杂，从午饭后一直看到晚上9点，才算初步搞清楚。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">下面就是我的笔记，主要用来整理自己的思路。但是，我尽量试图写得通俗易懂，希望能对其他朋友有用。毕竟，字符编码是计算机技术的基石，想要熟练使用计算机，就必须懂得一点字符编码的知识。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px"><strong style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: 800; TEXT-DECORATION: none; PADDING-TOP: 0px">1. ASCII码</strong></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">我们知道，在计算机内部，所有的信息最终都表示为一个二进制的字符串。每一个二进制位（bit）有0和1两种状态，因此八个二进制位就可以组合出256种状态，这被称为一个字节（byte）。也就是说，一个字节一共可以用来表示256种不同的状态，每一个状态对应一个符号，就是256个符号，从0000000到11111111。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">上个世纪60年代，美国制定了一套字符编码，对英语字符与二进制位之间的关系，做了统一规定。这被称为ASCII码，一直沿用至今。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">ASCII码一共规定了128个字符的编码，比如空格&#8220;SPACE&#8221;是32（二进制00100000），大写的字母A是65（二进制01000001）。这128个符号（包括32个不能打印出来的控制符号），只占用了一个字节的后面7位，最前面的1位统一规定为0。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px"><strong style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: 800; TEXT-DECORATION: none; PADDING-TOP: 0px">2、非ASCII编码</strong></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">英语用128个符号编码就够了，但是用来表示其他语言，128个符号是不够的。比如，在法语中，字母上方有注音符号，它就无法用ASCII码表示。于是，一些欧洲国家就决定，利用字节中闲置的最高位编入新的符号。比如，法语中的&#233;的编码为130（二进制10000010）。这样一来，这些欧洲国家使用的编码体系，可以表示最多256个符号。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">但是，这里又出现了新的问题。不同的国家有不同的字母，因此，哪怕它们都使用256个符号的编码方式，代表的字母却不一样。比如，130在法语编码中代表了&#233;，在希伯来语编码中却代表了字母Gimel (ג)，在俄语编码中又会代表另一个符号。但是不管怎样，所有这些编码方式中，0—127表示的符号是一样的，不一样的只是128—255的这一段。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">至于亚洲国家的文字，使用的符号就更多了，汉字就多达10万左右。一个字节只能表示256种符号，肯定是不够的，就必须使用多个字节表达一个符号。比如，简体中文常见的编码方式是GB2312，使用两个字节表示一个汉字，所以理论上最多可以表示256x256=65536个符号。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">中文编码的问题需要专文讨论，这篇笔记不涉及。这里只指出，虽然都是用多个字节表示一个符号，但是GB类的汉字编码与后文的Unicode和UTF-8是毫无关系的。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px"><strong style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: 800; TEXT-DECORATION: none; PADDING-TOP: 0px">3.Unicode</strong></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">正如上一节所说，世界上存在着多种编码方式，同一个二进制数字可以被解释成不同的符号。因此，要想打开一个文本文件，就必须知道它的编码方式，否则用错误的编码方式解读，就会出现乱码。为什么电子邮件常常出现乱码？就是因为发信人和收信人使用的编码方式不一样。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">可以想象，如果有一种编码，将世界上所有的符号都纳入其中。每一个符号都给予一个独一无二的编码，那么乱码问题就会消失。这就是Unicode，就像它的名字都表示的，这是一种所有符号的编码。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">Unicode当然是一个很大的集合，现在的规模可以容纳100多万个符号。每个符号的编码都不一样，比如，U+0639表示阿拉伯字母Ain，U+0041表示英语的大写字母A，U+4E25表示汉字&#8220;严&#8221;。具体的符号对应表，可以查询<a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(102,85,68); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: underline; PADDING-TOP: 0px" href="http://www.unicode.org/" target=_blank>unicode.org</a>，或者专门的<a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(102,85,68); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: underline; PADDING-TOP: 0px" href="http://www.chi2ko.com/tool/CJK.htm" target=_blank>汉字对应表</a>。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px"><strong style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: 800; TEXT-DECORATION: none; PADDING-TOP: 0px">4. Unicode的问题</strong></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">需要注意的是，Unicode只是一个符号集，它只规定了符号的二进制代码，却没有规定这个二进制代码应该如何存储。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">比如，汉字&#8220;严&#8221;的unicode是十六进制数4E25，转换成二进制数足足有15位（100111000100101），也就是说这个符号的表示至少需要2个字节。表示其他更大的符号，可能需要3个字节或者4个字节，甚至更多。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">这里就有两个严重的问题，第一个问题是，如何才能区别unicode和ascii？计算机怎么知道三个字节表示一个符号，而不是分别表示三个符号呢？第二个问题是，我们已经知道，英文字母只用一个字节表示就够了，如果unicode统一规定，每个符号用三个或四个字节表示，那么每个英文字母前都必然有二到三个字节是0，这对于存储来说是极大的浪费，文本文件的大小会因此大出二三倍，这是无法接受的。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">它们造成的结果是：1）出现了unicode的多种存储方式，也就是说有许多种不同的二进制格式，可以用来表示unicode。2）unicode在很长一段时间内无法推广，直到互联网的出现。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px"><strong style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: 800; TEXT-DECORATION: none; PADDING-TOP: 0px">5.UTF-8</strong></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">互联网的普及，强烈要求出现一种统一的编码方式。UTF-8就是在互联网上使用最广的一种unicode的实现方式。其他实现方式还包括UTF-16和UTF-32，不过在互联网上基本不用。<strong style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: 800; TEXT-DECORATION: none; PADDING-TOP: 0px">重复一遍，这里的关系是，UTF-8是Unicode的实现方式之一。</strong></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">UTF-8最大的一个特点，就是它是一种变长的编码方式。它可以使用1~4个字节表示一个符号，根据不同的符号而变化字节长度。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">UTF-8的编码规则很简单，只有二条：</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">1）对于单字节的符号，字节的第一位设为0，后面7位为这个符号的unicode码。因此对于英语字母，UTF-8编码和ASCII码是相同的。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">2）对于n字节的符号（n&gt;1），第一个字节的前n位都设为1，第n+1位设为0，后面字节的前两位一律设为10。剩下的没有提及的二进制位，全部为这个符号的unicode码。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">下表总结了编码规则，字母x表示可用编码的位。</p>
<blockquote style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 1em; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: rgb(224,223,204); LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 2em; PADDING-LEFT: 1em; PADDING-RIGHT: 1em; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 1em; border-top-left-radius: 20px 20px; border-top-right-radius: 20px 20px; border-bottom-right-radius: 20px 20px; border-bottom-left-radius: 20px 20px">
<div style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">Unicode符号范围 | UTF-8编码方式<br style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">(十六进制) | （二进制）<br style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">--------------------+---------------------------------------------<br style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">0000 0000-0000 007F | 0xxxxxxx<br style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">0000 0080-0000 07FF | 110xxxxx 10xxxxxx<br style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx<br style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx</p>
</div>
</blockquote>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">下面，还是以汉字&#8220;严&#8221;为例，演示如何实现UTF-8编码。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">已知&#8220;严&#8221;的unicode是4E25（100111000100101），根据上表，可以发现4E25处在第三行的范围内（0000 0800-0000 FFFF），因此&#8220;严&#8221;的UTF-8编码需要三个字节，即格式是&#8220;1110xxxx 10xxxxxx 10xxxxxx&#8221;。然后，从&#8220;严&#8221;的最后一个二进制位开始，依次从后向前填入格式中的x，多出的位补0。这样就得到了，&#8220;严&#8221;的UTF-8编码是&#8220;11100100 10111000 10100101&#8221;，转换成十六进制就是E4B8A5。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px"><strong style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: 800; TEXT-DECORATION: none; PADDING-TOP: 0px">6. Unicode与UTF-8之间的转换</strong></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">通过上一节的例子，可以看到&#8220;严&#8221;的Unicode码是4E25，UTF-8编码是E4B8A5，两者是不一样的。它们之间的转换可以通过程序实现。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">在Windows平台下，有一个最简单的转化方法，就是使用内置的记事本小程序Notepad.exe。打开文件后，点击&#8220;文件&#8221;菜单中的&#8220;另存为&#8221;命令，会跳出一个对话框，在最底部有一个&#8220;编码&#8221;的下拉条。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px"><a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(102,85,68); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: underline; PADDING-TOP: 0px" href="http://www.ruanyifeng.com/blog/2007/10/bg2007102801.jpg" target=_blank><img style="BORDER-BOTTOM: gray 1px solid; TEXT-ALIGN: left; BORDER-LEFT: gray 1px solid; PADDING-BOTTOM: 0px; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; COLOR: rgb(17,17,17); BORDER-TOP: gray 1px solid; FONT-WEIGHT: normal; BORDER-RIGHT: gray 1px solid; TEXT-DECORATION: none; PADDING-TOP: 0px" alt=bg2007102801.jpg src="http://www.ruanyifeng.com/blog/2007/10/bg2007102801-thumb.jpg" width=500 height=227></a></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">里面有四个选项：ANSI，Unicode，Unicode big endian 和 UTF-8。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">1）ANSI是默认的编码方式。对于英文文件是ASCII编码，对于简体中文文件是GB2312编码（只针对Windows简体中文版，如果是繁体中文版会采用Big5码）。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">2）Unicode编码指的是UCS-2编码方式，即直接用两个字节存入字符的Unicode码。这个选项用的little endian格式。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">3）Unicode big endian编码与上一个选项相对应。我在下一节会解释little endian和big endian的涵义。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">4）UTF-8编码，也就是上一节谈到的编码方法。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">选择完&#8221;编码方式&#8220;后，点击&#8221;保存&#8220;按钮，文件的编码方式就立刻转换好了。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px"><strong style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: 800; TEXT-DECORATION: none; PADDING-TOP: 0px">7. Little endian和Big endian</strong></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">上一节已经提到，Unicode码可以采用UCS-2格式直接存储。以汉字&#8221;严&#8220;为例，Unicode码是4E25，需要用两个字节存储，一个字节是4E，另一个字节是25。存储的时候，4E在前，25在后，就是Big endian方式；25在前，4E在后，就是Little endian方式。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">这两个古怪的名称来自英国作家斯威夫特的《格列佛游记》。在该书中，小人国里爆发了内战，战争起因是人们争论，吃鸡蛋时究竟是从大头(Big-Endian)敲开还是从小头(Little-Endian)敲开。为了这件事情，前后爆发了六次战争，一个皇帝送了命，另一个皇帝丢了王位。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">因此，第一个字节在前，就是&#8221;大头方式&#8220;（Big endian），第二个字节在前就是&#8221;小头方式&#8220;（Little endian）。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">那么很自然的，就会出现一个问题：计算机怎么知道某一个文件到底采用哪一种方式编码？</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">Unicode规范中定义，每一个文件的最前面分别加入一个表示编码顺序的字符，这个字符的名字叫做&#8221;零宽度非换行空格&#8220;（ZERO WIDTH NO-BREAK SPACE），用FEFF表示。这正好是两个字节，而且FF比FE大1。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">如果一个文本文件的头两个字节是FE FF，就表示该文件采用大头方式；如果头两个字节是FF FE，就表示该文件采用小头方式。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px"><strong style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: 800; TEXT-DECORATION: none; PADDING-TOP: 0px">8. 实例</strong></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">下面，举一个实例。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">打开&#8221;记事本&#8220;程序Notepad.exe，新建一个文本文件，内容就是一个&#8221;严&#8220;字，依次采用ANSI，Unicode，Unicode big endian 和 UTF-8编码方式保存。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">然后，用文本编辑软件<a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(102,85,68); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: underline; PADDING-TOP: 0px" href="http://www.google.cn/search?aq=t&amp;oq=UltraEdit&amp;complete=1&amp;hl=zh-CN&amp;newwindow=1&amp;rlz=1B3GGGL_zh-CNCN216CN216&amp;q=ultraedit+%E4%B8%8B%E8%BD%BD&amp;btnG=Google+%E6%90%9C%E7%B4%A2&amp;meta=" target=_blank>UltraEdit中</a>的&#8221;十六进制功能&#8220;，观察该文件的内部编码方式。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">1）ANSI：文件的编码就是两个字节&#8220;D1 CF&#8221;，这正是&#8220;严&#8221;的GB2312编码，这也暗示GB2312是采用大头方式存储的。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">2）Unicode：编码是四个字节&#8220;FF FE 25 4E&#8221;，其中&#8220;FF FE&#8221;表明是小头方式存储，真正的编码是4E25。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">3）Unicode big endian：编码是四个字节&#8220;FE FF 4E 25&#8221;，其中&#8220;FE FF&#8221;表明是大头方式存储。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">4）UTF-8：编码是六个字节&#8220;EF BB BF E4 B8 A5&#8221;，前三个字节&#8220;EF BB BF&#8221;表示这是UTF-8编码，后三个&#8220;E4B8A5&#8221;就是&#8220;严&#8221;的具体编码，它的存储顺序与编码顺序是一致的。</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px"><strong style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: 800; TEXT-DECORATION: none; PADDING-TOP: 0px">9. 延伸阅读</strong></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">*<span class=Apple-converted-space>&nbsp;</span><a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(102,85,68); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: underline; PADDING-TOP: 0px" href="http://www.joelonsoftware.com/articles/Unicode.html" target=_blank>The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets</a>（关于字符集的最基本知识）</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">*<span class=Apple-converted-space>&nbsp;</span><a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(102,85,68); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: underline; PADDING-TOP: 0px" href="http://www.pconline.com.cn/pcedu/empolder/gj/other/0505/616631.html" target=_blank>谈谈Unicode编码</a></p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">*<span class=Apple-converted-space>&nbsp;</span><a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(102,85,68); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: underline; PADDING-TOP: 0px" href="http://www.ietf.org/rfc/rfc3629.txt" target=_blank>RFC3629：UTF-8, a transformation format of ISO 10646</a>（如果实现UTF-8的规定）</p>
<p style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 28px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 1em 0px 0px 0.8em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">（完）</p>
</div>
</div>
<div style="BORDER-BOTTOM: rgb(211,211,211) 1px solid; TEXT-ALIGN: left; BORDER-LEFT: rgb(211,211,211) 1px solid; PADDING-BOTTOM: 1.5em; BACKGROUND-COLOR: rgb(222,235,247); LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 2em 0px 1em; PADDING-LEFT: 1.5em; PADDING-RIGHT: 1.5em; COLOR: rgb(252,178,151); BORDER-TOP: rgb(211,211,211) 1px solid; FONT-WEIGHT: bold; BORDER-RIGHT: rgb(211,211,211) 1px solid; TEXT-DECORATION: none; PADDING-TOP: 1.5em; border-top-left-radius: 10px 10px; border-top-right-radius: 10px 10px; border-bottom-right-radius: 10px 10px; border-bottom-left-radius: 10px 10px" class=asset-footer>
<h3 style="BORDER-BOTTOM: gray 1px solid; TEXT-ALIGN: left; PADDING-BOTTOM: 0.2em; BORDER-RIGHT-STYLE: none; TEXT-TRANSFORM: capitalize; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0.4em 0px 0.2em; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; LETTER-SPACING: -0.03em; COLOR: rgb(85,102,119); FONT-SIZE: 1.92em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: bold; TEXT-DECORATION: none; PADDING-TOP: 0px">文档信息</h3>
<ul style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: square; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 2em; PADDING-RIGHT: 2em; BORDER-TOP-STYLE: none; COLOR: rgb(17,17,17); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">
    <li style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 35px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: square; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(85,102,119); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">版权声明：自由转载-非商用-非衍生-保持署名 |<span class=Apple-converted-space>&nbsp;</span><a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(85,102,119); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" href="http://creativecommons.org/licenses/by-nc-nd/3.0/deed.zh">Creative Commons BY-NC-ND 3.0</a>
    <li style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 35px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: square; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(85,102,119); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">原文网址：<a style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: none; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(85,102,119); BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px" href="http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html">http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html</a>
    <li style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 35px; BORDER-RIGHT-STYLE: none; LIST-STYLE-TYPE: square; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP-STYLE: none; COLOR: rgb(85,102,119); FONT-SIZE: 1.6em; BORDER-LEFT-STYLE: none; FONT-WEIGHT: normal; TEXT-DECORATION: none; PADDING-TOP: 0px">最后修改时间：2007年10月29日 09:46 </li>
</ul>
</div>
</span></span>
<img src ="http://www.cppblog.com/lauer3912/aggbug/135312.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">lauer3912</a> 2010-12-02 23:30 <a href="http://www.cppblog.com/lauer3912/articles/135312.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>