<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>勿慢牛 &#187; 编程</title>
	<atom:link href="http://klniu.com/post/category/programme/feed/" rel="self" type="application/rss+xml" />
	<link>http://klniu.com</link>
	<description>『勿慢牛个人博客』</description>
	<lastBuildDate>Fri, 06 Jan 2012 06:42:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>在php数组内使用定界符</title>
		<link>http://klniu.com/post/delimiter-used-in-php-array/</link>
		<comments>http://klniu.com/post/delimiter-used-in-php-array/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 03:17:35 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=723</guid>
		<description><![CDATA[php在数组内也可以使用定界符，这样就不怕赋值的字符串内有单双引号了，使用如下: $families = array &#40; &#34;Griffin&#34;=&#62;array &#40; &#34;Peter&#34; =&#62; &#60;&#60;&#60;EOT lasdfjlsdfjsldfjslfjslfs\jdf EOT , &#34;Lois&#34;, &#34;Megan&#34; &#41; &#41;;]]></description>
			<content:encoded><![CDATA[<p>php在数组内也可以使用定界符，这样就不怕赋值的字符串内有单双引号了，使用如下:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$families</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span>
<span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">&quot;Griffin&quot;</span><span style="color: #339933;">=&gt;</span>array
  <span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">&quot;Peter&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOT
lasdfjlsdfjsldfjslfjslfs\jdf
EOT</span>
  <span style="color: #339933;">,</span>
  <span style="color: #0000ff;">&quot;Lois&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">&quot;Megan&quot;</span>
  <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/delimiter-used-in-php-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>syntaxhighlighter 动态加载</title>
		<link>http://klniu.com/post/syntaxhighlighter-dynamic-loading/</link>
		<comments>http://klniu.com/post/syntaxhighlighter-dynamic-loading/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 12:25:21 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[syntaxhighlighter]]></category>
		<category><![CDATA[动态]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=564</guid>
		<description><![CDATA[syntaxhighlighter 是一个高亮代码的好工具，我没有使用 wordpress 中的插件，而是自己去集成了它，不过每次都加载，是很慢的，于是就希望其能动态加载，官方在3.0版本里提供了动态加载的方法(autoloader 方法)，不过也是在预先加载两个核心 JS 的情况下才能实现的，这样的减肥方法不太吸引人，于是在网上寻找方法，看到下面文章：在WordPress指定页面加载指定JavaScript或CSS代码 文章中提到使用自定义字段的方法来动态加载 css 或者 js，这就是一个可以利用的地方，打造开始： 首先，在主题的 function.php 下添加如下函数，函数的作用是根据传递的参数来加载不同文件。其中的 $type 参数，可以是自己需要的字段，比如&#8221;cpp&#34;，&#8220;php&#34;等，我仅仅需要以下的几个，如果您想添加更多，仿照即可， shCore_all.css 是合并了 shCore.css 和 shThemeDefault.css 后的文件，您可以选择不合并，那么就需要加载两个 css 文件。 function loadCodeHighter($type) { $current_path = get_option('siteurl') .'/wp-content/themes/nopride/syntaxhighlighter/'; ?&#62; &#60;link type=&#34;text/css&#34; rel=&#34;stylesheet&#34; href=&#34;&#60;?php echo $current_path; ?&#62;styles/shCore_all.css&#34; /&#62; &#8230; <a href="http://klniu.com/post/syntaxhighlighter-dynamic-loading/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>syntaxhighlighter 是一个高亮代码的好工具，我没有使用 wordpress 中的插件，而是自己去集成了它，不过每次都加载，是很慢的，于是就希望其能动态加载，官方在3.0版本里提供了动态加载的方法(autoloader 方法)，不过也是在预先加载两个核心 JS 的情况下才能实现的，这样的减肥方法不太吸引人，于是在网上寻找方法，看到下面文章：<a href="http://loo2k.com/wordpress-page-javascript-css-code/" target="_blank">在WordPress指定页面加载指定JavaScript或CSS代码</a></p>
<p>文章中提到使用自定义字段的方法来动态加载 css 或者 js，这就是一个可以利用的地方，打造开始：</p>
<ul>
<li>首先，在主题的 function.php 下添加如下函数，函数的作用是根据传递的参数来加载不同文件。其中的 $type 参数，可以是自己需要的字段，比如&rdquo;cpp&quot;，&ldquo;php&quot;等，我仅仅需要以下的几个，如果您想添加更多，仿照即可， shCore_all.css 是合并了 shCore.css 和 shThemeDefault.css 后的文件，您可以选择不合并，那么就需要加载两个 css 文件。</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">function loadCodeHighter($type) {
    $current_path = get_option('siteurl') .'/wp-content/themes/nopride/syntaxhighlighter/';
	?&gt;
    &lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$current_path</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>styles/shCore_all.css&quot; /&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$current_path</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>scripts/shCore.js&quot;&gt;&lt;/script&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;cpp&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
      &lt;script type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$current_path</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>scripts/shBrushCpp.js&quot;&gt;&lt;/script&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;bash&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
      &lt;script type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$current_path</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>scripts/shBrushBash.js&quot;&gt;&lt;/script&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;css&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
      &lt;script type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$current_path</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>scripts/shBrushCss.js&quot;&gt;&lt;/script&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;php&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
      &lt;script type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$current_path</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>scripts/shBrushPhp.js&quot;&gt;&lt;/script&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
      &lt;script type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$current_path</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>scripts/shBrushPlain.js&quot;&gt;&lt;/script&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;script type=&quot;text/javascript&quot;&gt;
    SyntaxHighlighter.all()
    &lt;/script&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<ul>
<li>第二步，即是在主题的header.php文件内添加判断代码，如果当前页面是单个日志或者页面，go on，获得日志的关于&quot;code&quot;的自定义字段的值。如果不为空就传递给上述我们所定义的函数，函数根据字段来判断输出哪个高亮文件。这段代码可以添加在 &lt;?php wp_header() ?&gt; 之后，也可以在&lt;?php wp_footer() ?&gt; 之前，自己决定吧。</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$code</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'code'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$code</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    loadCodeHighter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<ul>
<li>第三步就是在撰写日志时在下面的自定域内添加名称为&quot;code&quot;的自定义域，值为函数内的字段，比如c++为cpp，php为php，您可以根据自己的函数定义来填写。之后我们就实现了在不同页面加载不同的高亮文件了，当然，没有自定义域&rdquo;code&quot;的文章是不加载的，因此也提高了速度。</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/syntaxhighlighter-dynamic-loading/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ckeditor for wordpress 添加 syntaxhighlighter 按钮</title>
		<link>http://klniu.com/post/add-syntaxhighlighter-button-ckeditor-for-wordpress/</link>
		<comments>http://klniu.com/post/add-syntaxhighlighter-button-ckeditor-for-wordpress/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 10:22:43 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[ckeditor]]></category>
		<category><![CDATA[syntaxhighlight]]></category>
		<category><![CDATA[syntaxhighlighter]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=563</guid>
		<description><![CDATA[代码的高亮一直来都是个问题，很多东西只能凑和着来，就像本文要说的 syntaxhighter 一样，解析真的好慢呀，不过高亮效果却是不错的。 在ckeditor for wordpress 的基础上添加 syntaxhighter 按钮支持，以方便添加代码，这个可不能少。修改步骤如下： SyntaxHighlighter Plugin 插件，此 ckeditor 插件是由&#160;Lajox 写的，项目地址：http://code.google.com/p/lajox/，下载 SyntaxHighlighter Plugin 即可，之后解压至 ckeditor for wordpress 插件目录下的 plugins 目录。 修改 ckeditor for wordpress 插件目录下&#160;ckeditor.config.js 文件，首先在&#160;config.toolbar_WordpressFull 字段下添加 syntaxhighlight 按钮，然后在下面调用插件，完整的 ckeditor.config.js 是类似于下面片断的： 在 wordpress 后台的 ckeditor for &#8230; <a href="http://klniu.com/post/add-syntaxhighlighter-button-ckeditor-for-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>代码的高亮一直来都是个问题，很多东西只能凑和着来，就像本文要说的 syntaxhighter 一样，解析真的好慢呀，不过高亮效果却是不错的<img alt="smiley" src="http://klniu.com/wordpress/wp-content/plugins/ckeditor-for-wordpress/ckeditor/plugins/smiley/images/regular_smile.gif" title="smiley" />。</p>
<p>在ckeditor for wordpress 的基础上添加 syntaxhighter 按钮支持，以方便添加代码，这个可不能少。修改步骤如下：</p>
<p><meta content="text/html; charset=utf-8" http-equiv="content-type" /></p>
<ol>
<li>SyntaxHighlighter Plugin 插件，此 ckeditor 插件是由&nbsp;Lajox 写的，项目地址：<a href="http://code.google.com/p/lajox/">http://code.google.com/p/lajox/</a>，下载 SyntaxHighlighter Plugin 即可，之后解压至 ckeditor for wordpress 插件目录下的 plugins 目录。</li>
<li>修改 ckeditor for wordpress 插件目录下&nbsp;ckeditor.config.js 文件，首先在&nbsp;config.toolbar_WordpressFull 字段下添加 syntaxhighlight 按钮，然后在下面调用插件，完整的 ckeditor.config.js 是类似于下面片断的：</li>
<li>在 wordpress 后台的 ckeditor for wordpress 插件选项中，修改 Basic settings 下&nbsp;<span class="Apple-style-span" style="font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 13px; border-collapse: collapse; line-height: 18px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Editor toolbar 为wordpress full，之后就可以在编辑的时候使用 wordpress full 工具栏了，而我们的syntaxhighlight便是在这个工具栏里面放着。至此，就完成了，粘贴代码来回切换源代码和可视窗口之间已经不会出现转义混乱的情况了，当然，有了 ckeditor 和这个按钮，应该不需要经常切换了吧。</span></li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">CKEDITOR.editorConfig = function(config) {
	// The minimum editor width, in pixels, when resizing it with the resize handle.
	config.resize_minWidth = 450;
&nbsp;
	// Protect PHP code tags (<span style="color: #000000; font-weight: bold;">&lt;?</span><span style="color: #339933;">...</span><span style="color: #000000; font-weight: bold;">?&gt;</span>) so CKEditor will not break them when
	// switching from Source to WYSIWYG.
	config.protectedSource.push(/&lt;\?[\s\S]*?\?&gt;/g);
&nbsp;
	// Define toolbars, you can remove or add buttons.
	// List of all buttons is here: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.toolbar_Full
&nbsp;
	// WordPress basic toolbar
	config.toolbar_WordpressBasic = [ [ 'Bold', 'Italic', '-', 'NumberedList','BulletedList', '-', 'Link', 'Unlink', 'Image' ] ];
&nbsp;
	// WordPress full toolbar
	config.toolbar_WordpressFull = [
			['Source'],
			['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
			['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
			['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
			'/',
			['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
			['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
			['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
			['Link','Unlink','Anchor'],
			'/',
			['Format','Font','FontSize'],
			['TextColor','BGColor'],
			['Maximize', 'ShowBlocks', 'syntaxhighlight'],['MediaEmbed']
		 ];
    config.extraPlugins += (config.extraPlugins ? ',syntaxhighlight' : 'syntaxhighlight' );
    CKEDITOR.plugins.addExternal('syntaxhighlight', ckeditorSettings.pluginPath + 'plugins/syntaxhighlight/');
};</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/add-syntaxhighlighter-button-ckeditor-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mac 与 IP 修改器</title>
		<link>http://klniu.com/post/mac-and-ip-trainer/</link>
		<comments>http://klniu.com/post/mac-and-ip-trainer/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 09:55:02 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[Qt]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[软件]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macmanager]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=561</guid>
		<description><![CDATA[因为经常要在不同的地点更换 mac 和 ip，所以就自己动手写了这个小工具。主要功能： 不重启计算机修改 mac。 修改网络地址参数，比如 ip、子网掩码、网关和 DNS。 也可以将上述参数通过 DHCP 来获取。 保存和读取配置，方便在不同地点调用不同的配置。 截图如下： 这个小工具是用 Qt 4.6.3 写成的，修改 mac 是通过更改注册表来完成的，之后调用 windows api 来实现网卡重启，这个是参考别人的代码。地址的修改是通过 netsh 命令完成的，工具开源，所以有兴趣的同学请给予指导，项目地址：http://code.google.com/p/klniu/ 因为库文件比较大，所以工具整体比较大，有两个版本，一个是动态链接版本，包含多个动态链接库。另一个是静态链接，是一个单文件，请大家自行选择使用。下载地址： 动态链接版本：http://klniu.googlecode.com/files/macmanager_1.0_dynamic.7z 静态链接版本：http://klniu.googlecode.com/files/macmanager_1.0_static.7z 源代码：http://klniu.googlecode.com/files/macmanager_1.0_src.7z]]></description>
			<content:encoded><![CDATA[<p>因为经常要在不同的地点更换 mac 和 ip，所以就自己动手写了这个小工具。主要功能：</p>
<ul>
<li>不重启计算机修改 mac。</li>
<li>修改网络地址参数，比如 ip、子网掩码、网关和 DNS。</li>
<li>也可以将上述参数通过 DHCP 来获取。</li>
<li>保存和读取配置，方便在不同地点调用不同的配置。</li>
</ul>
<p>截图如下：</p>
<p><img alt="macmanager" src="http://pic.klniu.com/klniu/201008/macmanager.png" style="width: 600px; height: 380px; " /></p>
<p>这个小工具是用 Qt 4.6.3 写成的，修改 mac 是通过更改注册表来完成的，之后调用 windows api 来实现网卡重启，这个是参考别人的代码。地址的修改是通过 netsh 命令完成的，工具开源，所以有兴趣的同学请给予指导，项目地址：<a href="http://code.google.com/p/klniu/" target="_blank">http://code.google.com/p/klniu/</a></p>
<p>因为库文件比较大，所以工具整体比较大，有两个版本，一个是动态链接版本，包含多个动态链接库。另一个是静态链接，是一个单文件，请大家自行选择使用。下载地址：</p>
<p>动态链接版本：<a href="http://klniu.googlecode.com/files/macmanager_1.0_dynamic.7z" target="_blank">http://klniu.googlecode.com/files/macmanager_1.0_dynamic.7z</a></p>
<p>静态链接版本：<a href="http://klniu.googlecode.com/files/macmanager_1.0_static.7z" target="_blank">http://klniu.googlecode.com/files/macmanager_1.0_static.7z</a></p>
<p>源代码：<a href="http://klniu.googlecode.com/files/macmanager_1.0_src.7z" target="_blank">http://klniu.googlecode.com/files/macmanager_1.0_src.7z</a></p>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/mac-and-ip-trainer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QNetworkInterface 类</title>
		<link>http://klniu.com/post/qnetworkinterface-class/</link>
		<comments>http://klniu.com/post/qnetworkinterface-class/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 06:02:01 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[Qt]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[QNetworkInterface]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=549</guid>
		<description><![CDATA[QNetworkInterface 是一个管理网络连接的类，利用他可以枚举本机的网络连接并获取其属性。比较常用的函数有： QList&#60;QNetworkAddressEntry&#62; QNetworkInterface::addressEntries() 获取地址列表，应用如下： //原型 QList&#60;QNetworkAddressEntry&#62; QNetworkInterface::addressEntries () const //比如获取本地所有 ip 和 netmask //allInterfaces() 是一个静态函数，用于获取本机所以连接。 QList&#60;QNetworkInterface&#62; networkInterface = QNetworkInterface::allInterfaces(); for (QList&#60;QNetworkInterface&#62;::const_iterator i = networkInterface.const_Begin(); i != networkInterface.const_End(); ++i) { //获取连接地址列表 QList&#60;QNetworkAddressEntry&#62; addressEntriesList = (*i).addressEntries(); for (QList&#60;QNetworkAddressEntry&#62;::const_iterator j = addressEntriesList.constBegin(); &#8230; <a href="http://klniu.com/post/qnetworkinterface-class/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
	QNetworkInterface 是一个管理网络连接的类，利用他可以枚举本机的网络连接并获取其属性。比较常用的函数有：
</p>
<ul>
<li>
		QList&lt;QNetworkAddressEntry&gt; QNetworkInterface::addressEntries() <span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;"><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">获取地址列表，应用如下：</span></span>
	</li>
</ul>
<pre class="brush: cpp">
//原型 QList&lt;QNetworkAddressEntry&gt; QNetworkInterface::addressEntries () const
//比如获取本地所有 ip 和 netmask
//allInterfaces() 是一个静态函数，用于获取本机所以连接。
QList&lt;QNetworkInterface&gt; networkInterface = QNetworkInterface::allInterfaces();
for (QList&lt;QNetworkInterface&gt;::const_iterator i = networkInterface.const_Begin(); i != networkInterface.const_End(); ++i) {
  //获取连接地址列表
  QList&lt;QNetworkAddressEntry&gt; addressEntriesList = (*i).addressEntries();
  for (QList&lt;QNetworkAddressEntry&gt;::const_iterator j = addressEntriesList.constBegin(); j != addressEntriesList.constEnd(); ++j) {
    //输出 ip
    qDebug() &lt;&lt; (*i).ip().toString();
    //输出 netmask
    qDebug() &lt;&lt; (*i).ip().toString();
  }
}
</pre>
<ul>
<li>
		QString QNetworkInterface::hardwareAddress() <span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">获取网卡</span> mac <span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">地址。例如，在上例中：</span>
	</li>
</ul>
<pre class="brush: cpp">
(*i).hardwareAddress();
</pre>
<ul>
<li>
		QString QNetworkInterface::name() 获取网卡名称。这个名称是系统分配的，是一个字符串，在 windows 平台，可以将此字符串作为参数传递给 api，用以获取或者设置其他 Qt 不能获取或设置的属性，比如网关、DNS、网卡类型、wins 服务器的获取与设置，可以参考 windows api 中的 getAdapterInfo 和 getPerAdaterInfo 来实现这些功能。
	</li>
<li>
		QNetworkInterface&nbsp;QNetworkInterface::interfaceFormName()，通过名称来获取一个QNetworkInterface的对象或指针，此处名称也是上述所指名称。
	</li>
<li>
		QString QNetworkInterface::humanReadableName()，获取网络连接名称，此处名称一般指&ldquo;本地连接&rdquo;、&ldquo;eth0&rdquo;及&ldquo;lo&rdquo;等。
	</li>
<li>
		int QNetworkInterface::index()，网卡索引，这是系统在启动时为网卡分配的索引，是一个整型值，当然也可以成为 Qt 与系统 api 之间的接口，就像上的是 name() 一样。
	</li>
<li>
		QNetworkInterface QNetworkInterface::interfaceFromIndex ( int index )，通过索引值来获取一个QNetworkInterface的对象或指针，此处索引值即为上述所指整型值。
	</li>
<li>
		QList&lt;QHostAddress&gt; QNetworkInterface::allAddresses ()，获取地址列表，此处只返回IP地址列表，所以如果只想获取IP地址的话，可以用此函数，例如：
	</li>
</ul>
<pre class="brush: cpp">
//allInterfaces() 是一个静态函数，用于获取本机所以连接。
QList&lt;QNetworkInterface&gt; networkInterface = QNetworkInterface::allInterfaces();
for (QList&lt;QNetworkInterface&gt;::const_iterator i = networkInterface.const_Begin(); i != networkInterface.const_End(); ++i) {
  //获取ip地址列表
  QList&lt;QHostAddress&gt; addressesList = (*i).allAddresses();
  for (QList&lt;QHostAddress&gt;::const_iterator j = addressesList.constBegin(); j != addressesList.constEnd(); ++j) {
    //输出 ip
    qDebug() &lt;&lt; (*i).toString();
  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/qnetworkinterface-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ 编程易犯错误-类指针成员未初始化</title>
		<link>http://klniu.com/post/c-programming-easy-to-make-mistakes-like-the-members-of-uninitialized-pointer/</link>
		<comments>http://klniu.com/post/c-programming-easy-to-make-mistakes-like-the-members-of-uninitialized-pointer/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 01:58:57 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[易犯错误]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=547</guid>
		<description><![CDATA[在 C++ 编程过程中，如果类体内声明的数据成员为指针变量，就需要在构造函数中初始化，否则就会出现内在不能为 written 的错误，因此导致程序退出，对于此，编译器并不提示，所以做到使用前初始化还是比较好的。]]></description>
			<content:encoded><![CDATA[<p>在 C++ 编程过程中，如果类体内声明的数据成员为指针变量，就需要在构造函数中初始化，否则就会出现内在不能为 written 的错误，因此导致程序退出，对于此，编译器并不提示，所以做到使用前初始化还是比较好的。</p>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/c-programming-easy-to-make-mistakes-like-the-members-of-uninitialized-pointer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QWizard下一步按钮的控制</title>
		<link>http://klniu.com/post/qwizard-next-button-control/</link>
		<comments>http://klniu.com/post/qwizard-next-button-control/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 10:32:59 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[Qt]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[QWizard]]></category>
		<category><![CDATA[QWizardPage]]></category>
		<category><![CDATA[按钮]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=544</guid>
		<description><![CDATA[QWizard是Qt的向导类，在向导过程中，可以通过函数registerField注册字段实现全局访问，而且可以通过4种方法来控制下一步或者完成按钮的可用性： 第一种方法，isComplete函数，其应用于QWizardPage，可控制单个向导页面的&#8220;下一步&#8221;或者&#8220;完成&#8221;按钮的可用性，函数如下： bool QWizardPage::isComplete () const[virtual] 下面是isComplete的实现，源码来源于 http://doc.qt.nokia.com/qq/qq22-qwizard.html#validatebeforeitstoolate 首先重新实现QWizardPage::isComplete()函数 bool SailingPage::isComplete() const { return field(&#34;sailing&#34;).toDate().dayOfWeek() != Qt::Sunday; } 连接输入框或者其他需要监视的对象的信号与QWizardPage::completeChanged ()信号。 connect(sailing, SIGNAL(selectionChanged()), this, SIGNAL(completeChanged())); 当然也可以自己执行QWizardPage::completeChanged ()信号，即自行编写完成检查函数后执行信号： emit completeChanged() 第二种方法，hasAcceptableInput函数，用于QLineEdit，如果hasAcceptableInput为false，则按钮会变灰。 bool hasAcceptableInput () const 第三种方法，registerField函数，第一个参数name后加星号，例如field*，就可以保证如果此区域不填写，下一步按钮将始处于灰色状态。 void QWizardPage::registerField ( const QString &#38; &#8230; <a href="http://klniu.com/post/qwizard-next-button-control/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
	QWizard是Qt的向导类，在向导过程中，可以通过函数registerField注册字段实现全局访问，而且可以通过4种方法来控制下一步或者完成按钮的可用性：</p>
<p>
	第一种方法，isComplete函数，其应用于QWizardPage，可控制单个向导页面的&ldquo;下一步&rdquo;或者&ldquo;完成&rdquo;按钮的可用性，函数如下：</p>
<pre class="brush:cpp;first-line:1;pad-line-numbers:true;highlight:null;">
bool QWizardPage::isComplete () const[virtual]</pre>
<p>
	下面是isComplete的实现，源码来源于</p>
<p>
	<a href="http://doc.qt.nokia.com/qq/qq22-qwizard.html#validatebeforeitstoolate" target="_blank">http://doc.qt.nokia.com/qq/qq22-qwizard.html#validatebeforeitstoolate</a></p>
<p>
	首先重新实现QWizardPage::isComplete()函数</p>
<pre class="brush:cpp">
bool SailingPage::isComplete() const
{
    return field(&quot;sailing&quot;).toDate().dayOfWeek() != Qt::Sunday;
}</pre>
<p>
	连接输入框或者其他需要监视的对象的信号与QWizardPage::completeChanged ()信号。</p>
<pre class="brush:cpp">
connect(sailing, SIGNAL(selectionChanged()), this, SIGNAL(completeChanged()));</pre>
<p>
	当然也可以自己执行QWizardPage::completeChanged ()信号，即自行编写完成检查函数后执行信号：</p>
<pre class="brush:cpp">
emit completeChanged()</pre>
<p>
	第二种方法，hasAcceptableInput函数，用于QLineEdit，如果hasAcceptableInput为false，则按钮会变灰。</p>
<pre class="brush:cpp">
bool hasAcceptableInput () const</pre>
<p>
	第三种方法，registerField函数，第一个参数name后加星号，例如field*，就可以保证如果此区域不填写，下一步按钮将始处于灰色状态。</p>
<pre class="brush:cpp">
void QWizardPage::registerField ( const QString &amp; name, QWidget * widget, const char * property = 0, const char * changedSignal = 0)</pre>
<p>
	第四种方法，重新实现bool QWizardPage::validatePage ()函数，其能在点击下一步或者完成按钮时完成函数所定义的功能，当然就包括验证这一类的东西了。</p>
<p><!--[syntaxhighlighter]--><br />
							  <!--代码高亮，请勿编辑--><br />
							  <script type="text/javascript" src="http://klniu.com/wordpress/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shCore.js"></script><br />
							  <script type="text/javascript" src="http://klniu.com/wordpress/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shBrushCpp.js"></script></p>
<link type="text/css" rel="stylesheet" href="http://klniu.com/wordpress/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/styles/shCoreCk.css" />
<link type="text/css" rel="stylesheet" href="http://klniu.com/wordpress/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/styles/shThemeCk.css" />
							  <script type="text/javascript">
							  //<![CDATA[
							  SyntaxHighlighter.defaults['class-name']	= '';
							  SyntaxHighlighter.defaults['smart-tabs']	= true;
							  SyntaxHighlighter.defaults['tab-size']	= 4;
							  SyntaxHighlighter.defaults['gutter']		= true;
							  SyntaxHighlighter.defaults['quick-code']	= true;
							  SyntaxHighlighter.defaults['collapse'] 	= true;
							  SyntaxHighlighter.defaults['auto-links']	= false;
							  SyntaxHighlighter.all();
							  //]]&gt;
							  </script><br />
							  <!--[/syntaxhighlighter]--><!--[syntaxhighlighter]--><br />
							  <!--代码高亮，请勿编辑--><br />
							  <script type="text/javascript" src="http://klniu.com/wordpress/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shCore.js"></script><br />
							  <script type="text/javascript" src="http://klniu.com/wordpress/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shBrushCpp.js"></script></p>
<link type="text/css" rel="stylesheet" href="http://klniu.com/wordpress/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/styles/shCoreCk.css" />
<link type="text/css" rel="stylesheet" href="http://klniu.com/wordpress/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/styles/shThemeCk.css" />
							  <script type="text/javascript">
							  //<![CDATA[
							  SyntaxHighlighter.defaults['class-name']	= '';
							  SyntaxHighlighter.defaults['smart-tabs']	= true;
							  SyntaxHighlighter.defaults['tab-size']	= 4;
							  SyntaxHighlighter.defaults['gutter']		= true;
							  SyntaxHighlighter.defaults['quick-code']	= true;
							  SyntaxHighlighter.defaults['collapse'] 	= true;
							  SyntaxHighlighter.defaults['auto-links']	= false;
							  SyntaxHighlighter.all();
							  //]]&gt;
							  </script><br />
							  <!--[/syntaxhighlighter]--></p>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/qwizard-next-button-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dokuwiki中文文件名及sitemap乱码的解决</title>
		<link>http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/</link>
		<comments>http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/#comments</comments>
		<pubDate>Sun, 30 May 2010 07:52:06 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[dokuwiki]]></category>
		<category><![CDATA[sitemap]]></category>
		<category><![CDATA[中文]]></category>
		<category><![CDATA[乱码]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=539</guid>
		<description><![CDATA[dokuwiki默认是使用urlencode函数对文件名进行编码后存储的，而索引文章的indexer.php文件在生成sitemap.xml时也会对文件名编码，这样对搜索引擎是不友好的，实际上将这两个编码的功能去掉就可以了。 中文文件名的乱码可以参考http://www.dokuwiki.org/zh:pagename进行更改，即: function utf8_encodeFN&#40;$file, $safe = true&#41; &#123; if &#40;$safe &#38;&#38; preg_match&#40;'#^[a-zA-Z0-9/_\-.%]+$#', $file&#41;&#41; &#123; return $file; &#125; /* 把这个部分注释掉 $file = urlencode($file); $file = str_replace('%2F','/',$file); */ return $file; &#125; &#125; if &#40;!function_exists&#40;'utf8_decodeFN'&#41;&#41; &#123; /** * URL-Decode a filename * * &#8230; <a href="http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>dokuwiki默认是使用urlencode函数对文件名进行编码后存储的，而索引文章的indexer.php文件在生成sitemap.xml时也会对文件名编码，这样对搜索引擎是不友好的，实际上将这两个编码的功能去掉就可以了。</p>
<p>中文文件名的乱码可以参考<a href="http://www.dokuwiki.org/zh:pagename">http://www.dokuwiki.org/zh:pagename</a>进行更改，即:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> utf8_encodeFN<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$safe</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$safe</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#^[a-zA-Z0-9/_\-.%]+$#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">/* 把这个部分注释掉
     $file = urlencode($file);
     $file = str_replace('%2F','/',$file);
   */</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utf8_decodeFN'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009933; font-style: italic;">/**
   * URL-Decode a filename
   *
   * This is just a wrapper around urldecode
   *
   * @author Andreas Gohr &lt;andi@splitbrain.org&gt;
   * @see urldecode
   */</span>
  <span style="color: #000000; font-weight: bold;">function</span> utf8_decodeFN<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//$file = urldecode($file); //再注释掉这个语句...</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>而生成sitemap.xml文件的是&quot;/lib/exe/indexer.php&quot;文件，打开这个文件，搜索runSitemapper()函数，在函数下有此语句：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'    &lt;loc&gt;'</span><span style="color: #339933;">.</span>wl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/loc&gt;'</span><span style="color: #339933;">.</span>NL<span style="color: #339933;">;</span></pre></div></div>

<p>其中wl函数为重写url的，在wl函数的定义在&quot;/inc/common.php&quot;文件内，其中有一语句：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$id</span>    <span style="color: #339933;">=</span> idfilter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>idfilter即是进行编码转换的，只需要在common.php中去掉那一行即可。</p>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QString, wchar_t *, TCHAR, CString和其他字符或字符串类型的转换</title>
		<link>http://klniu.com/post/qstring-wchar_t-tchar-and-other-types-of-conversion-characters-or-strings/</link>
		<comments>http://klniu.com/post/qstring-wchar_t-tchar-and-other-types-of-conversion-characters-or-strings/#comments</comments>
		<pubDate>Sat, 08 May 2010 11:15:30 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[Qt]]></category>
		<category><![CDATA[转载]]></category>
		<category><![CDATA[QString]]></category>
		<category><![CDATA[TCHAR]]></category>
		<category><![CDATA[wchar_t]]></category>
		<category><![CDATA[转换]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=533</guid>
		<description><![CDATA[这篇文章是在Blogspot上看到的一篇文章，能够解决QString, wchar_t *, TCHAR和其他字符或字符串类型之间的转换，方便在使用Windows API的时候转换的麻烦。 原文地址：http://tkrotoff.blogspot.com/2010/04/code-snippets-about-qstring-wchart.html //QString to wchar_t *: const wchar_t * encodedName = reinterpret_cast&#60;const wchar_t *&#62;(fileName.utf16()); //QString to char * given a file name: QByteArray fileName = QFile::encodeName(aFileName); const char * encodedName = fileName.constData(); //Valid as long as &#8230; <a href="http://klniu.com/post/qstring-wchar_t-tchar-and-other-types-of-conversion-characters-or-strings/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>这篇文章是在Blogspot上看到的一篇文章，能够解决QString, wchar_t *, TCHAR和其他字符或字符串类型之间的转换，方便在使用Windows API的时候转换的麻烦。</p>
<p>原文地址：<a href="http://tkrotoff.blogspot.com/2010/04/code-snippets-about-qstring-wchart.html">http://tkrotoff.blogspot.com/2010/04/code-snippets-about-qstring-wchart.html</a></p>
<pre class="brush:cpp;">//QString to wchar_t *:
const wchar_t * encodedName = reinterpret_cast&lt;const wchar_t *&gt;(fileName.utf16());

//QString to char * given a file name:
QByteArray fileName = QFile::encodeName(aFileName);
const char * encodedName = fileName.constData(); //Valid as long as fileName exists

//QString to char * (general case):
const char * tmp = str.toUtf8().constData();
[/code]
Windows 数据类型: http://msdn.microsoft.com/en-us/library/aa383751.aspx
[code lang=&quot;cpp&quot;]
//TCHAR:
#ifdef UNICODE
typedef wchar_t TCHAR;
#else
typedef char TCHAR;
#endif

//LPCTSTR:
#ifdef UNICODE
typedef LPCWSTR LPCTSTR;
#else
typedef LPCSTR LPCTSTR;
#endif

//LPCSTR:
typedef const char * LPCSTR;

//LPCWSTR:
typedef const wchar_t * LPCWSTR;

//LPCWSTR to QString:
QString text(QString::fromUtf16(reinterpret_cast&lt;const unsigned short *&gt;(tmp)));</pre>
<p>另一种解决办法是使用QString::fromWCharArray()，但这个函数可能导致一些尚未解决的wchar_t符号问题。</p>
<p>最佳的编程风格： 使用L来定义wchar_t宽字符串，比如 L&quot;text&quot; 字义了一个UNICODE字符串&quot;text&quot;。</p>
<p>今天又看到一个文章，关于字符串之间的转换，比较全面，在此将英文翻译并整理一下。<br />
	原文地址：http://hi.baidu.com/koko200147/blog/item/7e3cad828c9b9bb66d8119cb.html</p>
<p>QString与其他字符类型之间的转换，QString在Qt4中是UNICODE编码的，使用utf16规范。</p>
<pre class="brush:cpp;">QString::fromAscii ( const char * str, int size = -1 );
QString::fromLatin1 ( const char * str, int size = -1 );
QString::fromLocal8Bit ( const char * str, int size = -1 );
QString::fromRawData ( const QChar * unicode, int size );
QString::fromStdString ( const std::string &amp; str );
QString::fromStdWString ( const std::wstring &amp; str );
QString::fromUcs4 ( const uint * unicode, int size = -1 );
QString::fromUtf8 ( const char * str, int size = -1 );
QString::fromUtf16 ( const ushort * unicode, int size = -1 );
QString::fromWCharArray ( const wchar_t * string, int size = -1 );

//qstring -&gt;std::string
QString::toStdString () ;
QString::toStdWString ();

//BSTR&lt;-&gt;QString，不太了解BSTR是什么，还没用到过，所以不知道对不对
BSTR bstr_str;
QString q_str((QChar*)bstr_str, wcslen(bstr_str));
bstr_str = SysAllocString(q_str.utf16());//remember use SysFreeString on BSTR

//QString&lt;-&gt;LPCSTR
QString::toLocal8Bit().constData();
QString::fromLocal8Bit ( const char * str, int size = -1 );

//QString&lt;-&gt;LPCWSTR
QString::utf16();
QString::fromUtf16 ( const ushort * unicode, int size = -1 );

//QString&lt;-&gt;CString
CString c_str(qstring::utf16());
QString fromUtf16 (LPCTSTR(c_str) );</pre>
<p>CString转换为char*</p>
<pre class="brush:cpp;">//1.传给未分配内存的const char* （LPCTSTR）指针.
CString cstr(asdd);
const char* ch = (LPCTSTR)cstr;//ch指向的地址和cstr相同。但由于使用const保证ch不会修改，所以安全.

//2.传给未分配内存的指针.
CString cstr = &quot;ASDDSD&quot;;
char *ch = cstr.GetBuffer(cstr1.GetLength() + 1);
cstr.ReleaseBuffer();
//修改ch指向的值等于修改cstr里面的值.
//PS:用完ch后,不用delete ch,因为这样会破坏cstr内部空间,容易造成程序崩溃.

//3.第二种用法。把CString 值赋给已分配内存的char *。
CString cstr1 = &quot;ASDDSD&quot;;
int strLength = cstr1.GetLength() + 1;
char *pValue = new char[strLength];
strncpy(pValue, cstr1, strLength);

//4.第三种用法.把CString 值赋给已分配内存char[]数组.
CString cstr2 = &quot;ASDDSD&quot;;
int strLength1 = cstr1.GetLength() + 1;
char chArray[100];
memset(chArray,0, sizeof(bool) * 100); //将数组的垃圾内容清空.
strncpy(chArray, cstr1, strLength1);

//5.如果上述都不行，使用以下方法
CString origCString(&quot;Hello, World!&quot;);
wchar_t* wCharString = origCString.GetBuffer(origCString.GetLength()+1);
size_t origsize = wcslen(wCharString) + 1;
size_t convertedChars = 0;
char *CharString;
CharString=new char(origsize);
wcstombs_s(&amp;convertedChars, CharString, origsize, wCharString , _TRUNCATE);
cout &lt;&lt; CharString &lt;&lt; endl; //成功输出字符串&quot;Hello,World&quot;</pre>
<p>从UTF8编码到GB编码的字符串转换方法：</p>
<pre class="brush:cpp;">QString Utf8_To_GB(QString strText)
{
return QString::fromUtf8(strText.toLocal8Bit().data());
}</pre>
<p>从GB编码到UTF8编码的字符串转换方法：</p>
<pre class="brush:cpp;">QString GB_To_Utf8(char *strText)
{
return QString::fromLocal8Bit(strText);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/qstring-wchar_t-tchar-and-other-types-of-conversion-characters-or-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Qt中addStretch的有趣应用</title>
		<link>http://klniu.com/post/qt-interesting-applications-in-addstretch/</link>
		<comments>http://klniu.com/post/qt-interesting-applications-in-addstretch/#comments</comments>
		<pubDate>Sat, 08 May 2010 08:11:47 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[Qt]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[addstretch]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=532</guid>
		<description><![CDATA[今天在使用addStretch，布局的时候，发现addStretch竟然是可以平均分配的，有意思。比如： QVBoxLayout *buttonLayout = new QVBoxLayout; buttonLayout-&#62;addStretch(1); buttonLayout-&#62;addWidget(Button1); buttonLayout-&#62;addStretch(1); buttonLayout-&#62;addWidget(Button2); buttonLayout-&#62;addStretch(1); buttonLayout-&#62;addWidget(Button3); buttonLayout-&#62;addStretch(6); 您会发现，buttonLayout的布局将空白没有widget的地方分成了9份，然后按照您所规定的地方分配弹簧，于是布局起来就方便多了，以前没有发现这个，一直还为布局头疼呢，现在有点门路了。]]></description>
			<content:encoded><![CDATA[<p>今天在使用addStretch，布局的时候，发现addStretch竟然是可以平均分配的，有意思。比如：</p>
<pre class="brush:cpp;">QVBoxLayout *buttonLayout = new QVBoxLayout;
buttonLayout-&gt;addStretch(1);
buttonLayout-&gt;addWidget(Button1);
buttonLayout-&gt;addStretch(1);
buttonLayout-&gt;addWidget(Button2);
buttonLayout-&gt;addStretch(1);
buttonLayout-&gt;addWidget(Button3);
buttonLayout-&gt;addStretch(6);</pre>
<p>您会发现，buttonLayout的布局将空白没有widget的地方分成了9份，然后按照您所规定的地方分配弹簧，于是布局起来就方便多了，以前没有发现这个，一直还为布局头疼呢，现在有点门路了。</p>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/qt-interesting-applications-in-addstretch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

