﻿<?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/biao/category/9973.html</link><description> 我不聪明，但我会很努力</description><language>zh-cn</language><lastBuildDate>Tue, 15 Oct 2013 13:24:59 GMT</lastBuildDate><pubDate>Tue, 15 Oct 2013 13:24:59 GMT</pubDate><ttl>60</ttl><item><title>Qt：编码范围</title><link>http://www.cppblog.com/biao/archive/2013/10/15/203755.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 15 Oct 2013 12:45:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/10/15/203755.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/203755.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/10/15/203755.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/203755.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/203755.html</trackback:ping><description><![CDATA[<div>编码范围</div>
<div>1. GBK (GB2312/GB18030)</div>
<div>x00-xff GBK双字节编码范围</div>
<div>x20-x7f ASCII</div>
<div>xa1-xff 中文</div>
<div>x80-xff 中文</div>
<div><br />
</div>
<div>2. UTF-8 (Unicode)</div>
<div>u4e00-u9fa5 (中文)</div>
<div>x3130-x318F (韩文)</div>
<div>xAC00-xD7A3 (韩文)</div>
<div>u0800-u4e00 (日文)</div>
<div>ps: 韩文是大于[u9fa5]的字符</div>
<div><br />
</div>
<div>有时候我们也会用到全角英文、特殊符号等</div>
<div>全角英文的UTF8是: uff21 &#8211; uff5a ，是从大写A开始到小写的z。</div>
<div>utf8中的全角数字是 uff10 &#8211; uff19 ，对应关系自然是　０ &#8211; ９ 。</div>
<div>utf8中的 uff01 到 uff09 是我们美式键盘上shift + 从1到9键上的特殊符号。</div>
<div><br />
</div>
<div>utf8中的 uff20是@, 要注意的是因为@是 uff20，所以 uff02 是双引号，</div>
<div>6的&#8230;&#8230;是两个符号的组合，</div>
<div>也就是说ff06是＆， ff09是 ）。</div>
<div><br />
</div>
<div>正则例子（使用PHP）:</div>
<div>preg_replace(&#8220;/([x80-xff])/&#8221;,&#8221;",$str); //GBK中匹配</div>
<div>preg_replace(&#8220;/([u4e00-u9fa5])/&#8221;,&#8221;",$str); //UTF8中匹配</div>
<div><br />
</div>
<div>转载地址：http://blog.csdn.net/sjw890821sjw/article/details/7004474</div>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/203755.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-10-15 20:45 <a href="http://www.cppblog.com/biao/archive/2013/10/15/203755.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：Windows Qt 去掉选中的虚线框</title><link>http://www.cppblog.com/biao/archive/2013/09/03/202977.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 02 Sep 2013 19:19:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/09/03/202977.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202977.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/09/03/202977.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202977.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202977.html</trackback:ping><description><![CDATA[<span  style="border-collapse: separate; font-family: Helvetica; line-height: normal; border-spacing: 0px; font-size: medium; ">class myStyle: public QProxyStyle<br />
{<br />
public:<br />
&nbsp; &nbsp;myStyle(QStyle *baseStyle)<br />
&nbsp; &nbsp; &nbsp; &nbsp;: QProxyStyle(baseStyle)<br />
&nbsp; &nbsp;{<br />
&nbsp; &nbsp;}<br />
<br />
&nbsp; &nbsp;void drawPrimitive(PrimitiveElement element,<br />
&nbsp; &nbsp; &nbsp; &nbsp;const QStyleOption *option,<br />
&nbsp; &nbsp; &nbsp; &nbsp;QPainter *painter,<br />
&nbsp; &nbsp; &nbsp; &nbsp;const QWidget *widget = 0) const<br />
&nbsp; &nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp;if (element == QStyle::PE_FrameFocusRect)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;<br />
&nbsp; &nbsp; &nbsp; &nbsp;QProxyStyle::drawPrimitive(element, option, painter, widget);<br />
&nbsp; &nbsp;}<br />
};&nbsp;</span>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/202977.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-09-03 03:19 <a href="http://www.cppblog.com/biao/archive/2013/09/03/202977.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：定制qDebug等输出的格式</title><link>http://www.cppblog.com/biao/archive/2013/09/02/202956.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 02 Sep 2013 09:48:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/09/02/202956.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202956.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/09/02/202956.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202956.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202956.html</trackback:ping><description><![CDATA[<br />
<pre style="margin-top: 0px; margin-bottom: 0px; "><hr />
</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #808000; font-size: 12pt; ">void</span><span style="color: #c0c0c0; "> </span><span style="font-size: 12pt; ">testMessagePattern()</span><span style="color: #c0c0c0; "> </span><span style="font-size: 12pt; ">{</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style="color: #800080; font-size: 12pt; ">QString</span><span style=" color:#c0c0c0;"> </span><span style="font-size: 12pt; ">QT_MESSAGE_PATTERN=</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">            </span><span style="color: #008000; font-size: 12pt; ">"[%{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}]"</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">            </span><span style="color: #008000; font-size: 12pt; ">":</span><span style=" color:#c0c0c0;"> </span><span style="color: #008000; font-size: 12pt; ">%{file}:%{line}</span><span style=" color:#c0c0c0;"> </span><span style="color: #008000; font-size: 12pt; ">-</span><span style=" color:#c0c0c0;"> </span><span style="color: #008000; font-size: 12pt; ">%{message}"</span><span style="font-size: 12pt; ">;</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style="font-size: 12pt; ">qSetMessagePattern(QT_MESSAGE_PATTERN);</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style="color: #000080; font-size: 12pt; ">qDebug</span><span style="font-size: 12pt; ">()</span><span style=" color:#c0c0c0;"> </span><span style="font-size: 12pt; ">&lt;&lt;</span><span style=" color:#c0c0c0;"> </span><span style="color: #008000; font-size: 12pt; ">"Hello</span><span style=" color:#c0c0c0;"> </span><span style="color: #008000; font-size: 12pt; ">Pattern"</span><span style="font-size: 12pt; ">;</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style="color: #000080; font-size: 12pt; ">qDebug</span><span style="font-size: 12pt; ">()</span><span style=" color:#c0c0c0;"> </span><span style="font-size: 12pt; ">&lt;&lt;</span><span style=" color:#c0c0c0;"> </span><span style="color: #800080; font-size: 12pt; ">QString</span><span style="font-size: 12pt; ">(</span><span style="color: #008000; font-size: 12pt; ">"黄彪"</span><span style="font-size: 12pt; ">).toUtf8().toHex();</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style="font-size: 12pt; ">}</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><hr />
</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; ">
<p style="margin: 0px; "><span style="font-family: Monaco; font-size: 10pt; color: #aa0000; ">[D]: /Users/Biao/Dropbox/workspace/Qt/Test/main.cpp:26 - Hello Pattern </span></p>
<p style="margin: 0px; "><span style="font-family: Monaco; font-size: 10pt; color: #aa0000; ">[D]: /Users/Biao/Dropbox/workspace/Qt/Test/main.cpp:28 - "e9bb84e5bdaa" </span></p>
<hr />
<h3 class="fn" style="font-size: 14px; line-height: 16px; font-family: Arial; margin: 45px 0px 0px; border: 1px solid #e6e6e6; border-top-left-radius: 7px; border-top-right-radius: 7px; border-bottom-right-radius: 7px; border-bottom-left-radius: 7px; background-color: #f6f6f6; word-spacing: 3px; padding: 5px; max-width: 75%; color: #313131; text-align: justify; white-space: normal; "><span class="type" style="color: #808080;">void</span>&nbsp;<span class="name" style="max-width: 75%; font-weight: 100; color: #1a1a1a;">qSetMessagePattern</span>(const&nbsp;<span class="type" style="color: #808080;"><a href="qthelp://org.qt-project.qtcore.511/qtcore/qstring.html" style="color: #007330; text-decoration: none; text-align: left;">QString</a></span>&nbsp;&amp;<em>&nbsp;pattern</em>)</h3>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; white-space: normal; ">Changes the output of the default message handler.</p>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; white-space: normal; ">Allows to tweak the output of&nbsp;<a href="qthelp://org.qt-project.qtcore.511/qtcore/qtglobal.html#qDebug" style="color: #007330; text-decoration: none; text-align: left;">qDebug</a>(),&nbsp;<a href="qthelp://org.qt-project.qtcore.511/qtcore/qtglobal.html#qWarning" style="color: #007330; text-decoration: none; text-align: left;">qWarning</a>(),&nbsp;<a href="qthelp://org.qt-project.qtcore.511/qtcore/qtglobal.html#qCritical" style="color: #007330; text-decoration: none; text-align: left;">qCritical</a>() and&nbsp;<a href="qthelp://org.qt-project.qtcore.511/qtcore/qtglobal.html#qFatal" style="color: #007330; text-decoration: none; text-align: left;">qFatal</a>().</p>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; white-space: normal; ">Following placeholders are supported:</p>
<table class="generic" style="border-top-left-radius: 7px; border-top-right-radius: 7px; border-bottom-right-radius: 7px; border-bottom-left-radius: 7px; background-color: #f6f6f6; margin-bottom: 25px; margin-left: 15px; font-size: 12px; line-height: 1.2; color: #313131; font-family: Arial, Helvetica; text-align: justify; ">
    <thead style="text-align: left; padding-left: 20px; background-color: #e1e0e0; border-left-style: none; border-right-style: none;">
        <tr class="qt-style">
            <th style="padding: 5px 10px; ">Placeholder</th><th style="padding: 5px 10px; ">Description</th>
        </tr>
    </thead>
    <tbody>
        <tr valign="top" class="odd" style="color: #66666e; ">
            <td style="padding: 3px 15px 3px 20px; "><tt style="text-align: left;">%{appname}</tt></td>
            <td style="padding: 3px 15px 3px 20px; "><a href="qthelp://org.qt-project.qtcore.511/qtcore/qcoreapplication.html#applicationName-prop" style="color: #007330; text-decoration: none; text-align: left;">QCoreApplication::applicationName</a>()</td>
        </tr>
        <tr valign="top" class="even" style="background-color: white; color: #66666e;">
            <td style="padding: 3px 15px 3px 20px; "><tt style="text-align: left;">%{file}</tt></td>
            <td style="padding: 3px 15px 3px 20px; ">Path to source file</td>
        </tr>
        <tr valign="top" class="odd" style="color: #66666e; ">
            <td style="padding: 3px 15px 3px 20px; "><tt style="text-align: left;">%{function}</tt></td>
            <td style="padding: 3px 15px 3px 20px; ">Function</td>
        </tr>
        <tr valign="top" class="even" style="background-color: white; color: #66666e;">
            <td style="padding: 3px 15px 3px 20px; "><tt style="text-align: left;">%{line}</tt></td>
            <td style="padding: 3px 15px 3px 20px; ">Line in source file</td>
        </tr>
        <tr valign="top" class="odd" style="color: #66666e; ">
            <td style="padding: 3px 15px 3px 20px; "><tt style="text-align: left;">%{message}</tt></td>
            <td style="padding: 3px 15px 3px 20px; ">The actual message</td>
        </tr>
        <tr valign="top" class="even" style="background-color: white; color: #66666e;">
            <td style="padding: 3px 15px 3px 20px; "><tt style="text-align: left;">%{pid}</tt></td>
            <td style="padding: 3px 15px 3px 20px; "><a href="qthelp://org.qt-project.qtcore.511/qtcore/qcoreapplication.html#applicationPid" style="color: #007330; text-decoration: none; text-align: left;">QCoreApplication::applicationPid</a>()</td>
        </tr>
        <tr valign="top" class="odd" style="color: #66666e; ">
            <td style="padding: 3px 15px 3px 20px; "><tt style="text-align: left;">%{threadid}</tt></td>
            <td style="padding: 3px 15px 3px 20px; ">ID of current thread</td>
        </tr>
        <tr valign="top" class="even" style="background-color: white; color: #66666e;">
            <td style="padding: 3px 15px 3px 20px; "><tt style="text-align: left;">%{type}</tt></td>
            <td style="padding: 3px 15px 3px 20px; ">"debug", "warning", "critical" or "fatal"</td>
        </tr>
    </tbody>
</table>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; white-space: normal; ">You can also use conditionals on the type of the message using&nbsp;<tt style="text-align: left;">%{if-debug}</tt>,&nbsp;<tt style="text-align: left;">%{if-warning}</tt>,&nbsp;<tt style="text-align: left;">%{if-critical}</tt>&nbsp;or&nbsp;<tt style="text-align: left;">%{if-fatal}</tt>&nbsp;followed by an&nbsp;<tt style="text-align: left;">%{endif}</tt>. What is inside the<tt style="text-align: left;">%{if-*}</tt>&nbsp;and&nbsp;<tt style="text-align: left;">%{endif}</tt>&nbsp;will only be printed if the type matches.</p>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; white-space: normal; ">Example:</p>
<pre class="cpp" style="border-top-left-radius: 7px; border-top-right-radius: 7px; border-bottom-right-radius: 7px; border-bottom-left-radius: 7px; background-color: #f6f6f6; border: 1px solid #e6e6e6; border-collapse: separate; margin: 10px; font-size: 12px; line-height: 1.2; overflow: auto; padding: 20px; color: #313131; text-align: justify; ">QT_MESSAGE_PATTERN<span class="operator">=</span><span class="string">"[%{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}"</span></pre>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; white-space: normal; ">The default&nbsp;<em>pattern</em>&nbsp;is "%{message}".</p>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; white-space: normal; ">The&nbsp;<em>pattern</em>&nbsp;can also be changed at runtime by setting the QT_MESSAGE_PATTERN environment variable; if both qSetMessagePattern() is called and QT_MESSAGE_PATTERN is set, the environment variable takes precedence.</p>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; white-space: normal; ">qSetMessagePattern() has no effect if a custom message handler is installed.</p>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; white-space: normal; ">This function was introduced in QtCore 5.0.</p>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; white-space: normal; "><strong>See also&nbsp;</strong><a href="qthelp://org.qt-project.qtcore.511/qtcore/qtglobal.html#qInstallMessageHandler" style="color: #007330; text-decoration: none; text-align: left;">qInstallMessageHandler</a>() and Debugging Techniques.</p>
<br />
</pre><img src ="http://www.cppblog.com/biao/aggbug/202956.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-09-02 17:48 <a href="http://www.cppblog.com/biao/archive/2013/09/02/202956.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：给QWidget添加shadow效果</title><link>http://www.cppblog.com/biao/archive/2013/09/02/202949.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 02 Sep 2013 07:19:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/09/02/202949.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202949.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/09/02/202949.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202949.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202949.html</trackback:ping><description><![CDATA[@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div><hr />
</div>
<img src="http://www.cppblog.com/images/cppblog_com/biao/QGraphicsDropShadowEffect.png" alt="" />
<div><hr />
<pre style="margin-top: 0px; margin-bottom: 0px; "><!--StartFragment--><span style=" color:#800080;">Widget</span>::Widget(<span style=" color:#800080;">QWidget</span><span style=" color:#c0c0c0;"> </span>*parent)<span style=" color:#c0c0c0;"> </span>:<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">QWidget</span>(parent),</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800000;">ui</span>(<span style=" color:#808000;">new</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">Ui</span>::<span style=" color:#800080;">Widget</span>),<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">data</span>(<span style=" color:#808000;">new</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">WidgetPrivate</span>)<span style=" color:#c0c0c0;"> </span>{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800000;">ui</span>-&gt;setupUi(<span style=" color:#808000;">this</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><br />
</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">QGraphicsBlurEffect</span><span style=" color:#c0c0c0;"> </span>*effect<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">new</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">QGraphicsBlurEffect</span>(<span style=" color:#808000;">this</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>effect-&gt;setBlurRadius(<span style=" color:#000080;">1.5</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><br />
</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">QGraphicsDropShadowEffect</span><span style=" color:#c0c0c0;"> </span>*shadowEffect<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">new</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">QGraphicsDropShadowEffect</span>(<span style=" color:#808000;">this</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>shadowEffect-&gt;setBlurRadius(<span style=" color:#000080;">5</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>shadowEffect-&gt;setXOffset(<span style=" color:#000080;">2</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>shadowEffect-&gt;setYOffset(<span style=" color:#000080;">2</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><br />
</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800000;">ui</span>-&gt;<span style=" color:#800000;">checkBox</span>-&gt;setGraphicsEffect(shadowEffect);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; ">}<!--EndFragment--></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><hr />
</pre>
</div><img src ="http://www.cppblog.com/biao/aggbug/202949.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-09-02 15:19 <a href="http://www.cppblog.com/biao/archive/2013/09/02/202949.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：Q_DECLARE_METATYPE和qRegisterMetaType</title><link>http://www.cppblog.com/biao/archive/2013/09/02/202948.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 02 Sep 2013 07:16:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/09/02/202948.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202948.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/09/02/202948.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202948.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202948.html</trackback:ping><description><![CDATA[@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#008000;">Adding</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">a</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">Q_DECLARE_METATYPE()</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">makes</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">the</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">type</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">known</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">to</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">all</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">template</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">based</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">functions,</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">including</span><span style=" color:#c0c0c0;"> </span><span style="color: red; ">QVariant.</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#008000;">Note</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">that</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">if</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">you</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">intend</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">to</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">use</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">the</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">type</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">in</span><span style=" color:#c0c0c0;"> </span><span style="color: red; ">queued</span><span style=" color:#c0c0c0;"> </span><span style="color: red; ">signal</span><span style=" color:#c0c0c0;"> </span><span style="color: red; ">and</span><span style=" color:#c0c0c0;"> </span><span style="color: red; ">slot</span><span style=" color:#c0c0c0;"> </span><span style="color: red; ">connections</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">or</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">in</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">QObject's</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">property</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">system,</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#008000;">you</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">also</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">have</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">to</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">call</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">qRegisterMetaType()</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">since</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">the</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">names</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">are</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">resolved</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">at</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">runtime.</span><!--EndFragment--></pre>
</div>
<div><hr />
</div>
<div>
<pre style="margin-top: 0px; margin-bottom: 0px; "><!--StartFragment--><span style=" color:#808000;">class</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">BH</span><span style=" color:#c0c0c0;"> </span>{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#808000;">public</span>:</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">BH</span>()<span style=" color:#c0c0c0;"> </span>{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">        </span><span style=" color:#800000;">value</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">10</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>}</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><br />
</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">int</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">value</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; ">};</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><br />
</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#000080;">Q_DECLARE_METATYPE</span>(BH)<!--EndFragment--></pre>
</div>
<div></div>
<div><hr />
</div>
<div><span style="color: #800080; ">BH</span><span style="color: #c0c0c0; "> </span>bh;</div>
<div>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#800080;">QVariant</span><span style=" color:#c0c0c0;"> </span>var<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">QVariant</span>::fromValue(bh);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><br />
</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#000080;">qDebug</span>()<span style=" color:#c0c0c0;"> </span>&lt;&lt;<span style=" color:#c0c0c0;"> </span>var.canConvert&lt;<span style=" color:#800080;">BH</span>&gt;();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><br />
</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#800080;">BH</span><span style=" color:#c0c0c0;"> </span>bh2<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>var.value&lt;<span style=" color:#800080;">BH</span>&gt;();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#000080;">qDebug</span>()<span style=" color:#c0c0c0;"> </span>&lt;&lt;<span style=" color:#c0c0c0;"> </span>bh2.<span style=" color:#800000;">value</span>;<!--EndFragment--></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><br />
</pre>
</div><img src ="http://www.cppblog.com/biao/aggbug/202948.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-09-02 15:16 <a href="http://www.cppblog.com/biao/archive/2013/09/02/202948.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：绘制带高光的按钮</title><link>http://www.cppblog.com/biao/archive/2013/08/07/202387.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 06 Aug 2013 23:32:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/08/07/202387.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202387.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/08/07/202387.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202387.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202387.html</trackback:ping><description><![CDATA[@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<img src="http://www.cppblog.com/images/cppblog_com/biao/Button.png" width="403" height="383" alt="" />&nbsp;
<div><br />
<div>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000FF; ">void</span>&nbsp;Widget::paintEvent(QPaintEvent&nbsp;*)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;QPainter&nbsp;painter(<span style="color: #0000FF; ">this</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.translate(width()&nbsp;/&nbsp;2,&nbsp;height()&nbsp;/&nbsp;2);<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.setRenderHint(QPainter::Antialiasing);<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.setPen(Qt::transparent);<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.fillRect(-width(),&nbsp;-height(),&nbsp;width()&nbsp;*&nbsp;2,&nbsp;height()&nbsp;*&nbsp;2,&nbsp;Qt::gray);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;radius&nbsp;=&nbsp;100;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;外边框</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;QLinearGradient&nbsp;lg1(0,&nbsp;-radius,&nbsp;0,&nbsp;radius);<br />
&nbsp;&nbsp;&nbsp;&nbsp;lg1.setColorAt(0,&nbsp;QColor(255,&nbsp;255,&nbsp;255));<br />
&nbsp;&nbsp;&nbsp;&nbsp;lg1.setColorAt(1,&nbsp;QColor(166,&nbsp;166,&nbsp;166));<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.setBrush(lg1);<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.drawEllipse(-radius,&nbsp;-radius,&nbsp;radius&nbsp;&lt;&lt;&nbsp;1,&nbsp;radius&nbsp;&lt;&lt;&nbsp;1);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;内边框</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;radius&nbsp;-=&nbsp;13;<br />
&nbsp;&nbsp;&nbsp;&nbsp;QLinearGradient&nbsp;lg2(0,&nbsp;-radius,&nbsp;0,&nbsp;radius);<br />
&nbsp;&nbsp;&nbsp;&nbsp;lg2.setColorAt(0,&nbsp;QColor(155,&nbsp;155,&nbsp;155));<br />
&nbsp;&nbsp;&nbsp;&nbsp;lg2.setColorAt(1,&nbsp;QColor(255,&nbsp;255,&nbsp;255));<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.setBrush(lg2);<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.drawEllipse(-radius,&nbsp;-radius,&nbsp;radius&nbsp;&lt;&lt;&nbsp;1,&nbsp;radius&nbsp;&lt;&lt;&nbsp;1);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;内部的圆</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;radius&nbsp;-=&nbsp;4;<br />
&nbsp;&nbsp;&nbsp;&nbsp;QRadialGradient&nbsp;rg(0,&nbsp;0,&nbsp;radius);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rg.setColorAt(0,&nbsp;QColor(245,&nbsp;0,&nbsp;0));<br />
&nbsp;&nbsp;&nbsp;&nbsp;rg.setColorAt(0.6,&nbsp;QColor(210,&nbsp;0,&nbsp;0));<br />
&nbsp;&nbsp;&nbsp;&nbsp;rg.setColorAt(1,&nbsp;QColor(140,&nbsp;0,&nbsp;0));<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.setBrush(rg);<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.drawEllipse(-radius,&nbsp;-radius,&nbsp;radius&nbsp;&lt;&lt;&nbsp;1,&nbsp;radius&nbsp;&lt;&lt;&nbsp;1);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;高光</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;radius&nbsp;-=&nbsp;3;<br />
&nbsp;&nbsp;&nbsp;&nbsp;QPainterPath&nbsp;path;<br />
&nbsp;&nbsp;&nbsp;&nbsp;path.addEllipse(-radius,&nbsp;-radius&nbsp;-&nbsp;2,&nbsp;radius&nbsp;&lt;&lt;&nbsp;1,&nbsp;radius&nbsp;&lt;&lt;&nbsp;1);<br />
&nbsp;&nbsp;&nbsp;&nbsp;QPainterPath&nbsp;bigEllipse;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;radius&nbsp;*=&nbsp;2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;bigEllipse.addEllipse(-radius,&nbsp;-radius&nbsp;+&nbsp;140,&nbsp;radius&nbsp;&lt;&lt;&nbsp;1,&nbsp;radius&nbsp;&lt;&lt;&nbsp;1);<br />
&nbsp;&nbsp;&nbsp;&nbsp;path&nbsp;-=&nbsp;bigEllipse;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;QLinearGradient&nbsp;lg3(0,&nbsp;-radius&nbsp;/&nbsp;2,&nbsp;0,&nbsp;0);<br />
&nbsp;&nbsp;&nbsp;&nbsp;lg3.setColorAt(0,&nbsp;QColor(255,&nbsp;255,&nbsp;255,&nbsp;220));<br />
&nbsp;&nbsp;&nbsp;&nbsp;lg3.setColorAt(1,&nbsp;QColor(255,&nbsp;255,&nbsp;255,&nbsp;30));<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.setBrush(lg3);<br />
&nbsp;&nbsp;&nbsp;&nbsp;painter.drawPath(path);<br />
}</div>
</div>
</div><img src ="http://www.cppblog.com/biao/aggbug/202387.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-08-07 07:32 <a href="http://www.cppblog.com/biao/archive/2013/08/07/202387.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：FontMetrics</title><link>http://www.cppblog.com/biao/archive/2013/08/03/202322.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 03 Aug 2013 10:27:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/08/03/202322.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202322.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/08/03/202322.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202322.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202322.html</trackback:ping><description><![CDATA[<div>在一个Rect的正中间绘制文本: rect的中点与文本的中点重合.</div>
<div>
<div>int cx = rect.x + rect.width / 2;</div>
<div>int fx = cx - fm.width(text);</div>
</div>
<div><br />
</div>
<div>int cy = rect.y + rect.height / 2;</div>
<div>int fy = cy + fm.xHeight&nbsp;/ 2;</div>
<div><br />
</div>
<div><br />
</div>
<div><br />
</div>
<img src="http://www.cppblog.com/images/cppblog_com/biao/FontMetrics.png" width="506" height="274" alt="" />
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/202322.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-08-03 18:27 <a href="http://www.cppblog.com/biao/archive/2013/08/03/202322.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mac：Mac下安装PHP, MySql开发环境</title><link>http://www.cppblog.com/biao/archive/2013/08/03/202319.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 03 Aug 2013 02:24:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/08/03/202319.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202319.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/08/03/202319.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202319.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202319.html</trackback:ping><description><![CDATA[最简单的两个选择: XAMPP, MAMP
<div>都集成了&nbsp;<span style="color: red; ">MySql + PhpMyAdmin&nbsp;</span>+ PHP 开发环境，建立开发环境简单（都只需要安装一个程序）。</div>
<div>如果单独的安装MySql，PhpMyAdmin，PHP开发环境，会麻烦很多。</div>
<div><br />
<div><span style="color: red; ">XAMPP</span>: 提供多平台版本:&nbsp;Mac,&nbsp;Windows，Linux, Solaris，但是几乎不更新了，相对MAMP来说易用性就差那么一点点。</div>
<div>下载地址：<a href="http://www.apachefriends.org/zh_cn/xampp.html">http://www.apachefriends.org/zh_cn/xampp.html</a></div>
<div><span style="color: red; "><br />
</span></div>
<div><span style="color: red; ">MAMP</span>: 只能运行于Mac，经常更新，帮助文档丰富，易用性更好。</div>
<div>下载地址：<a href="http://www.mamp.info/en/index.html">http://www.mamp.info/en/index.html</a></div>
<div><img src="http://www.cppblog.com/images/cppblog_com/biao/MAMP.png" width="537" height="458" alt="" /><br />
</div>
<div><img src="http://www.cppblog.com/images/cppblog_com/biao/MAMP-Preferences.png" width="537" height="458" alt="" /><br />
</div>
<div><br />
</div>
</div><img src ="http://www.cppblog.com/biao/aggbug/202319.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-08-03 10:24 <a href="http://www.cppblog.com/biao/archive/2013/08/03/202319.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：无标题栏无边框程序的拖动和改变大小</title><link>http://www.cppblog.com/biao/archive/2013/07/11/201704.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 11 Jul 2013 11:45:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/07/11/201704.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/201704.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/07/11/201704.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/201704.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/201704.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; ">From: <a href="http://blog.csdn.net/kfbyj/article/details/9284923">http://blog.csdn.net/kfbyj/article/details/9284923</a></span></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; "><br />
</span></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; ">最近做项目遇到的问题，总结下。</span></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; "></span>有时候我们觉得系统的标题栏和按钮太丑太呆板，想做自己的标题栏以及最大化、最小化、关闭，菜单按钮，我们就需要&nbsp;</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "></p>
<div class="dp-highlighter bg_cpp" style="width: 722px; text-align: left; line-height: 26px; ">
<div class="bar">
<div class="tools" style="border-left-color: #999999; "><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="ViewSource" title="view plain">view plain</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="CopyToClipboard" title="copy">copy</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="PrintSource" title="print">print</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="About" title="?">?</a>
<div style="position: absolute; left: 393px; top: 524px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_1" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-cpp">
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">setWindowFlags(Qt::FramelessWindowHint);&nbsp;&nbsp;</li>
</ol>
</div>
<span style="font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">但是这样过后，我们就不能拖动窗口改变位置，以及拖动边缘改变窗口大小了。</span>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; "></span>有两种方案处理这种情况：</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">1.自己对mouseMoveEvent,mousePressEvent,mouseReleaseEvent 等事件进行处理。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">2.Qt可以处理windows的消息。大家重新实现bool winEvent(MSG *message, long *result);(在此又一次感觉Qt的NB)</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><br />
</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; "></span>我刚开始使用第一种方法去实现的。移动窗口很容易做，大家可以去看看这个大大写的，比网上其他版本问题少些。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><a href="http://blog.csdn.net/aqtata/article/details/8902889" style="color: #ca0000; text-decoration: none; "><span style="white-space: pre; "></span>http://blog.csdn.net/aqtata/article/details/8902889</a><br />
</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; "></span>在窗口边缘按下鼠标拖动改变窗口大小就比较麻烦了。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; "></span>我是这样做的：</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">在mousePressEvent 按下设置m_bPressed为真。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">在mouseMoveEvent中m_bPressed为真且event-&gt;x() 在窗口边缘 及处理算出鼠标移动的增量 然后不断resize窗口。<br />
</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">至于如何为边缘的断定，就自己设定一个 差值 假如 在窗口边缘 &#177;4个px 就算在在该边缘就处理该resize。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">这样做缺点很多，1.拖快了不行，很容易超过该差值 ， 2.窗口抖动的厉害，一直在resize，3.要处理太多情况</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><br />
</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鉴于上诉缺点于是乎就到处问人百度google。有了第二种方法：</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; "></span>第二种方法很好用，效果和有标题边框程序一样~~~</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">Qt居然可以处理windows消息。。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">这里我们要重新实现winEvent ( MSG * message, long * result )&nbsp;</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">该虚函数在QWidget和QWizard以及QSizeGrip以及他们的子类中都可以实现。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; "></span>如果你想停止Qt处理消息就返回true，并且设置result到你想要保存的值返回给window处理。否者的话返回false。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">这里我们主要想处理WM_NCHITTEST消息。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">The&nbsp;<strong>WM_NCHITTEST</strong>&nbsp;message is sent to a window in order to determine what part of the window corresponds to a particular screen coordinate. This can happen, for example, when the cursor moves, when a mouse button is pressed or released, or in response to a call to a function such as&nbsp;<a class="mtps-internal-link" href="http://127.0.0.1:47873/help/1-6004/ms.help?method=page&amp;id=VS%7CWINUI%7C%7E%5CWINUI%5CWINDOWSUSERINTERFACE%5CWINDOWING%5CWINDOWS%5CWINDOWREFERENCE%5CWINDOWFUNCTIONS%5CWINDOWFROMPOINT.HTM&amp;product=VS&amp;productVersion=100&amp;topicVersion=85&amp;locale=ZH-CN&amp;topicLocale=EN-US" target="" style="color: #ca0000; text-decoration: none; "><strong>WindowFromPoint</strong></a>. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">A window receives this message through its&nbsp;<a class="mtps-internal-link" href="http://127.0.0.1:47873/help/1-6004/ms.help?method=page&amp;id=VS%7CWINUI%7C%7E%5CWINUI%5CWINDOWSUSERINTERFACE%5CWINDOWING%5CWINDOWPROCEDURES%5CWINDOWPROCEDUREREFERENCE%5CWINDOWPROCEDUREFUNCTIONS%5CWINDOWPROC.HTM&amp;product=VS&amp;productVersion=100&amp;topicVersion=85&amp;locale=ZH-CN&amp;topicLocale=EN-US" target="" style="color: #ca0000; text-decoration: none; "><strong>WindowProc</strong></a>&nbsp;function.&nbsp;</p>
<span style="font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">WM_NCHITTEST的消息响应函数会根据鼠标当前的坐标来判断鼠标命中了窗口的哪个部位，消息响应函数的返回值指出了部位，例如它可能会返回HTCAPTION，或者HTCLIENT等。（其返回值有很多，请查阅MSDN）。</span><br style="font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><span style="white-space: pre; "></span>知道这个就好了，我们还是要判断下鼠标的位置，然后通过该位置保存到result给window处理。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">其实就是我们的程序没有边框不能发送这些消息，我们把它告诉windows，然后windows帮我们处理拖动，改变大小等效果。所以效果和有边框有标题程序效果一样的。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">头文件申明：</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "></p>
<div class="dp-highlighter bg_cpp" style="width: 722px; text-align: left; line-height: 26px; ">
<div class="bar">
<div class="tools" style="border-left-color: #999999; "><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="ViewSource" title="view plain">view plain</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="CopyToClipboard" title="copy">copy</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="PrintSource" title="print">print</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="About" title="?">?</a>
<div style="position: absolute; left: 393px; top: 1462px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_2" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_2" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-cpp">
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; "><span class="keyword" style="color: blue; ">class</span>&nbsp;MainWindow&nbsp;:&nbsp;<span class="keyword" style="color: blue; ">public</span>&nbsp;QMainWindow&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">{&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;Q_OBJECT&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; "><span class="keyword" style="color: blue; ">public</span>:&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;MainWindow(QWidget&nbsp;*parent&nbsp;=&nbsp;0);&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;~MainWindow();&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; "><span class="keyword" style="color: blue; ">protected</span>:&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="datatypes" style="color: #2e8b57; font-weight: bold; ">bool</span>&nbsp;winEvent(MSG&nbsp;*message,&nbsp;<span class="datatypes" style="color: #2e8b57; font-weight: bold; ">long</span>&nbsp;*result);&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">};&nbsp;&nbsp;</li>
</ol>
</div>
<span style="font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">CPP实现</span><br style="font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "></p>
<div class="dp-highlighter bg_cpp" style="width: 722px; text-align: left; line-height: 26px; ">
<div class="bar">
<div class="tools" style="border-left-color: #999999; "><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="ViewSource" title="view plain">view plain</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="CopyToClipboard" title="copy">copy</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="PrintSource" title="print">print</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="About" title="?">?</a>
<div style="position: absolute; left: 393px; top: 1730px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_3" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_3" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-cpp">
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; "><span class="datatypes" style="color: #2e8b57; font-weight: bold; ">bool</span>&nbsp;MainWindow::winEvent(MSG&nbsp;*message,&nbsp;<span class="datatypes" style="color: #2e8b57; font-weight: bold; ">long</span>&nbsp;*result)&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">{&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">switch</span>(message-&gt;message)&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">case</span>&nbsp;WM_NCHITTEST:&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="datatypes" style="color: #2e8b57; font-weight: bold; ">int</span>&nbsp;xPos&nbsp;=&nbsp;GET_X_LPARAM(message-&gt;lParam)&nbsp;-&nbsp;<span class="keyword" style="color: blue; ">this</span>-&gt;frameGeometry().x();&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="datatypes" style="color: #2e8b57; font-weight: bold; ">int</span>&nbsp;yPos&nbsp;=&nbsp;GET_Y_LPARAM(message-&gt;lParam)&nbsp;-&nbsp;<span class="keyword" style="color: blue; ">this</span>-&gt;frameGeometry().y();&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">if</span>(<span class="keyword" style="color: blue; ">this</span>-&gt;childAt(xPos,yPos)&nbsp;==&nbsp;0)&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*result&nbsp;=&nbsp;HTCAPTION;&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<span class="keyword" style="color: blue; ">else</span>{&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">return</span>&nbsp;<span class="keyword" style="color: blue; ">false</span>;&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">if</span>(xPos&nbsp;&gt;&nbsp;18&nbsp;&amp;&amp;&nbsp;xPos&nbsp;&lt;&nbsp;22)&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*result&nbsp;=&nbsp;HTLEFT;&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">if</span>(xPos&nbsp;&gt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;width()&nbsp;-&nbsp;22)&nbsp;&amp;&amp;&nbsp;xPos&nbsp;&lt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;width()&nbsp;-&nbsp;18))&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*result&nbsp;=&nbsp;HTRIGHT;&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">if</span>(yPos&nbsp;&gt;&nbsp;18&nbsp;&amp;&amp;&nbsp;yPos&nbsp;&lt;&nbsp;22)&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*result&nbsp;=&nbsp;HTTOP;&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">if</span>(yPos&nbsp;&gt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;height()&nbsp;-&nbsp;22)&nbsp;&amp;&amp;&nbsp;yPos&nbsp;&lt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;height()&nbsp;-&nbsp;18))&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*result&nbsp;=&nbsp;HTBOTTOM;&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">if</span>(xPos&nbsp;&gt;&nbsp;18&nbsp;&amp;&amp;&nbsp;xPos&nbsp;&lt;&nbsp;22&nbsp;&amp;&amp;&nbsp;yPos&nbsp;&gt;&nbsp;18&nbsp;&amp;&amp;&nbsp;yPos&nbsp;&lt;&nbsp;22)&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*result&nbsp;=&nbsp;HTTOPLEFT;&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">if</span>(xPos&nbsp;&gt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;width()&nbsp;-&nbsp;22)&nbsp;&amp;&amp;&nbsp;xPos&nbsp;&lt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;width()&nbsp;-&nbsp;18)&nbsp;&amp;&amp;&nbsp;yPos&nbsp;&gt;&nbsp;18&nbsp;&amp;&amp;&nbsp;yPos&nbsp;&lt;&nbsp;22)&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*result&nbsp;=&nbsp;HTTOPRIGHT;&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">if</span>(xPos&nbsp;&gt;&nbsp;18&nbsp;&amp;&amp;&nbsp;xPos&nbsp;&lt;&nbsp;22&nbsp;&amp;&amp;&nbsp;yPos&nbsp;&gt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;height()&nbsp;-&nbsp;22)&nbsp;&amp;&amp;&nbsp;yPos&nbsp;&lt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;height()&nbsp;-&nbsp;18))&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*result&nbsp;=&nbsp;HTBOTTOMLEFT;&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">if</span>(xPos&nbsp;&gt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;width()&nbsp;-&nbsp;22)&nbsp;&amp;&amp;&nbsp;xPos&nbsp;&lt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;width()&nbsp;-&nbsp;18)&nbsp;&amp;&amp;&nbsp;yPos&nbsp;&gt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;height()&nbsp;-&nbsp;22)&nbsp;&amp;&amp;&nbsp;yPos&nbsp;&lt;&nbsp;(<span class="keyword" style="color: blue; ">this</span>-&gt;height()&nbsp;-&nbsp;18))&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*result&nbsp;=&nbsp;HTBOTTOMRIGHT;&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">return</span>&nbsp;<span class="keyword" style="color: blue; ">true</span>;&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: blue; ">return</span>&nbsp;<span class="keyword" style="color: blue; ">false</span>;&nbsp;&nbsp;</li>
    <li class="" style="border-left-color: #999999; background-color: #f5fae2; color: #555555; line-height: 18px; ">}&nbsp;&nbsp;</li>
</ol>
</div>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">把各种边界情况保存到result给windows处理，我们就省去很多事情，我想windows肯定比我们自己实现的效果要好多了。</p>
<span style="font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">以上的18 以及 22 是我对程序的边缘进行判断的范围。</span>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">因为</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">我做了边框阴影。阴影边框设定为20px所以在</p>
<div class="dp-highlighter bg_cpp" style="width: 722px; text-align: left; line-height: 26px; ">
<div class="bar">
<div class="tools" style="border-left-color: #999999; "><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="ViewSource" title="view plain">view plain</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="CopyToClipboard" title="copy">copy</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="PrintSource" title="print">print</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="About" title="?">?</a>
<div style="position: absolute; left: 393px; top: 2588px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_4" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_4" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-cpp">
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">xPos&nbsp;&gt;&nbsp;18&nbsp;&amp;&amp;&nbsp;xPos&nbsp;&lt;&nbsp;22&nbsp;其实就是我们假定的边框了。&nbsp;&nbsp;</li>
</ol>
</div>
<div class="dp-highlighter bg_cpp" style="width: 722px; text-align: left; line-height: 26px; ">
<div class="bar">
<div class="tools" style="border-left-color: #999999; "><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="ViewSource" title="view plain">view plain</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="CopyToClipboard" title="copy">copy</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="PrintSource" title="print">print</a><a href="http://blog.csdn.net/kfbyj/article/details/9284923#" class="About" title="?">?</a>
<div style="position: absolute; left: 393px; top: 2650px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_5" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_5" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=5&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-cpp">
    <li class="alt" style="border-left-color: #999999; background-color: #f5fae2; line-height: 18px; ">&nbsp;&nbsp;</li>
    <li></li>
</ol>
</div>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/201704.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-07-11 19:45 <a href="http://www.cppblog.com/biao/archive/2013/07/11/201704.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：Use Third Party Libraries</title><link>http://www.cppblog.com/biao/archive/2013/06/28/201358.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 27 Jun 2013 23:31:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/06/28/201358.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/201358.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/06/28/201358.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/201358.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/201358.html</trackback:ping><description><![CDATA[<div class="descr" style="margin-top: 35px; margin-left: 5px; text-align: justify; vertical-align: top; color: #313131; font-family: Arial, Helvetica; line-height: 16px; ">
<p style="line-height: 20px;">Using a third-party library with Qt is a simple process. Suppose you know of a cross-platform library that accepts audio samples of a cat's meows and translates them into English words. This library is named&nbsp;<tt style="text-align: left;">CatWhisperer</tt>, and has several files that it provides as part of its library. Your project,&nbsp;<tt style="text-align: left;">MyQtApp</tt>, stores these files in a folder named&nbsp;<tt style="text-align: left;">3rdparty</tt>:</p>
<ul style="padding-bottom: 2px;">
    <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">MyQtApp/
    <ul style="padding-bottom: 2px;">
        <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">MyQtApp.pro</li>
        <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">src/
        <ul style="padding-bottom: 2px;">
            <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">main.cpp</li>
        </ul>
        </li>
        <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">3rdparty/
        <ul style="padding-bottom: 2px;">
            <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">CatWhisperer
            <ul style="padding-bottom: 2px;">
                <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">include/
                <ul style="padding-bottom: 2px;">
                    <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">CatWhisperer.h</li>
                </ul>
                </li>
                <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">lib/
                <ul style="padding-bottom: 2px;">
                    <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">libCatWhisperer.so</li>
                    <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">CatWhisperer.lib</li>
                </ul>
                </li>
                <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">bin/
                <ul style="padding-bottom: 2px;">
                    <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">CatWhisperer.dll</li>
                </ul>
                </li>
            </ul>
            </li>
        </ul>
        </li>
    </ul>
    </li>
</ul>
<p style="line-height: 20px;">To use the&nbsp;<tt style="text-align: left;">CatWhisperer</tt>&nbsp;library in&nbsp;<tt style="text-align: left;">MyQtApp</tt>,&nbsp;<tt style="text-align: left;">qmake</tt>&nbsp;requires the location and names of the&nbsp;<tt style="text-align: left;">CatWhisperer</tt>&nbsp;libraries. Optionally, you can also:</p>
<ul style="padding-bottom: 2px;">
    <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">Provide the location of the&nbsp;<tt>CatWhisperer</tt>&nbsp;source code so that you don't have to type out the full path to each file when you include them in your own code.</li>
    <li style="margin-bottom: 10px; padding-left: 8px; list-style: square outside; text-align: left;">Choose the destination in which the&nbsp;<tt>MyQtApp</tt>&nbsp;executable will be created.</li>
</ul>
<p style="line-height: 20px;">The information above is provided in the&nbsp;<tt style="text-align: left;">.pro</tt>&nbsp;file, so that&nbsp;<tt style="text-align: left;">qmake</tt>&nbsp;can parse it and produce makefiles. Makefiles contain all the information needed by your compiler and linker to produce output, whether it is an executable, another library file, etc. The next sections explain the syntax with which&nbsp;<tt style="text-align: left;">qmake</tt>expects you to provide this information.</p>
<a name="source-code" style="width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>
<h2 style="font-size: 16px; line-height: 1.2; font-family: Arial; font-weight: 100; background-color: #f2f3f4; padding: 4px; margin-bottom: 30px; margin-top: 30px; border-top-color: #e0e0de; border-top-width: 1px; border-top-style: solid; border-bottom-color: #e0e0de; border-bottom-width: 1px; border-bottom-style: solid; max-width: 99%; overflow: hidden; ">Source code</h2>
<p style="line-height: 20px;">To be able to write</p>
<pre class="cpp" style="border-top-left-radius: 7px; border-top-right-radius: 7px; border-bottom-right-radius: 7px; border-bottom-left-radius: 7px; background-color: #f6f6f6; border: 1px solid #e6e6e6; border-collapse: separate; margin: 10px; font-size: 12px; line-height: 1.2; overflow: auto; padding: 20px; "><span class="preprocessor">#include &lt;CatWhisperer.h&gt;</span></pre>
<p style="line-height: 20px;">instead of</p>
<pre class="cpp" style="border-top-left-radius: 7px; border-top-right-radius: 7px; border-bottom-right-radius: 7px; border-bottom-left-radius: 7px; background-color: #f6f6f6; border: 1px solid #e6e6e6; border-collapse: separate; margin: 10px; font-size: 12px; line-height: 1.2; overflow: auto; padding: 20px; "><span class="preprocessor">#include &lt;3rdparty/CatWhisperer/include/CatWhisperer.h&gt;</span></pre>
<p style="line-height: 20px;">you can provide the path to the&nbsp;<tt style="text-align: left;">CatWhisperer</tt>&nbsp;<tt style="text-align: left;">include</tt>&nbsp;directory, using the INCLUDEPATH variable:</p>
<pre class="cpp" style="border-top-left-radius: 7px; border-top-right-radius: 7px; border-bottom-right-radius: 7px; border-bottom-left-radius: 7px; background-color: #f6f6f6; border: 1px solid #e6e6e6; border-collapse: separate; margin: 10px; font-size: 12px; line-height: 1.2; overflow: auto; padding: 20px; ">INCLUDEPATH <span class="operator">+</span><span class="operator">=</span> <span class="number">3rdparty</span><span class="operator">/</span>CatWhisperer<span class="operator">/</span><span class="keyword">include</span></pre>
<a name="library-files" style="width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>
<h2 style="font-size: 16px; line-height: 1.2; font-family: Arial; font-weight: 100; background-color: #f2f3f4; padding: 4px; margin-bottom: 30px; margin-top: 30px; border-top-color: #e0e0de; border-top-width: 1px; border-top-style: solid; border-bottom-color: #e0e0de; border-bottom-width: 1px; border-bottom-style: solid; max-width: 99%; overflow: hidden; ">Library files</h2>
<p style="line-height: 20px;">To let&nbsp;<tt style="text-align: left;">qmake</tt>&nbsp;know where to find the&nbsp;<tt style="text-align: left;">CatWhisperer</tt>&nbsp;library files, use the LIBS variable:</p>
<pre class="cpp" style="border-top-left-radius: 7px; border-top-right-radius: 7px; border-bottom-right-radius: 7px; border-bottom-left-radius: 7px; background-color: #f6f6f6; border: 1px solid #e6e6e6; border-collapse: separate; margin: 10px; font-size: 12px; line-height: 1.2; overflow: auto; padding: 20px; ">LIBS <span class="operator">+</span><span class="operator">=</span> <span class="operator">-</span>L<span class="string">"3rdparty/CatWhisperer/lib"</span> <span class="operator">-</span>lCatWhisperer</pre>
<p style="line-height: 20px;">The first part of the expression lets the linker know in which directory it should look for the library files. The double quotes are only necessary when the path contains spaces, so we could have omitted them in this example.</p>
<p style="line-height: 20px;">The second part tells the linker which libraries to link against. We have two different library files for UNIX platforms and Windows, respectively:<tt style="text-align: left;">libCatWhisperer.so</tt>&nbsp;and&nbsp;<tt style="text-align: left;">CatWhisperer.lib</tt>. It is not necessary to specify the&nbsp;<tt style="text-align: left;">.lib</tt>&nbsp;extension, nor the&nbsp;<tt style="text-align: left;">lib</tt>&nbsp;prefix (on UNIX platforms).</p>
<a name="destination-directory" style="width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>
<h2 style="font-size: 16px; line-height: 1.2; font-family: Arial; font-weight: 100; background-color: #f2f3f4; padding: 4px; margin-bottom: 30px; margin-top: 30px; border-top-color: #e0e0de; border-top-width: 1px; border-top-style: solid; border-bottom-color: #e0e0de; border-bottom-width: 1px; border-bottom-style: solid; max-width: 99%; overflow: hidden; ">Destination directory</h2>
<p style="line-height: 20px;">By default,&nbsp;<tt style="text-align: left;">qmake</tt>&nbsp;creates the executable in the same directory as the&nbsp;<tt style="text-align: left;">.pro</tt>&nbsp;file. We can choose our own directory using the DESTDIR variable:</p>
<pre class="cpp" style="border-top-left-radius: 7px; border-top-right-radius: 7px; border-bottom-right-radius: 7px; border-bottom-left-radius: 7px; background-color: #f6f6f6; border: 1px solid #e6e6e6; border-collapse: separate; margin: 10px; font-size: 12px; line-height: 1.2; overflow: auto; padding: 20px; ">DESTDIR <span class="operator">=</span> bin</pre>
<p style="line-height: 20px;">That's it! You can now use the&nbsp;<tt style="text-align: left;">CatWhisperer</tt>&nbsp;library in your project. The final&nbsp;<tt style="text-align: left;">.pro</tt>&nbsp;file looks like this:</p>
<pre class="cpp" style="border-top-left-radius: 7px; border-top-right-radius: 7px; border-bottom-right-radius: 7px; border-bottom-left-radius: 7px; background-color: #f6f6f6; border: 1px solid #e6e6e6; border-collapse: separate; margin: 10px; font-size: 12px; line-height: 1.2; overflow: auto; padding: 20px; ">TARGET <span class="operator">=</span> MyQtApp
TEMPLATE <span class="operator">=</span> app
INCLUDEPATH <span class="operator">+</span><span class="operator">=</span> <span class="number">3rdparty</span><span class="operator">/</span>CatWhisperer<span class="operator">/</span><span class="keyword">include</span>
SOURCES <span class="operator">+</span><span class="operator">=</span> src<span class="operator">/</span>main<span class="operator">.</span>cpp
LIBS <span class="operator">+</span><span class="operator">=</span> <span class="operator">-</span>L<span class="string">"3rdparty/CatWhisperer/lib"</span> <span class="operator">-</span>lCatWhisperer</pre>
</div>
<p style="line-height: 20px; color: #313131; font-family: Arial, Helvetica; text-align: justify; "><strong>See also&nbsp;</strong><a href="qthelp://org.qt-project.qtdoc.510/qtdoc/qmake-manual.html" style="color: #007330; text-decoration: none; text-align: left;">qmake Manual</a>&nbsp;and Adding Libraries to Projects.</p>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/201358.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-06-28 07:31 <a href="http://www.cppblog.com/biao/archive/2013/06/28/201358.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：解读Q_GLOBAL_STATIC(QFontDatabasePrivate, privateDb)  </title><link>http://www.cppblog.com/biao/archive/2013/06/26/201312.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 26 Jun 2013 02:02:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/06/26/201312.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/201312.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/06/26/201312.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/201312.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/201312.html</trackback:ping><description><![CDATA[<span style="color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 24.545454025268555px; background-color: #ffffff;">From:&nbsp;</span><a href="http://zhgw01.blog.163.com/blog/static/1041481220105253491586/">http://zhgw01.blog.163.com/blog/static/1041481220105253491586/</a><br /><span style="color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 24.545454025268555px; background-color: #ffffff;">根据 src/corelib/global.h</span><br style="line-height: 24.545454025268555px; color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ffffff;" /><table border="1" cellpadding="1" cellspacing="1" width="80%" style="line-height: 24.545454025268555px; color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 13.63636302947998px; background-color: #ffffff;"><tbody><tr><td>&nbsp;template &lt;typename T&gt;<br />class QGlobalStatic<br />{<br />public:<br />&nbsp;&nbsp;&nbsp; T *pointer;<br />&nbsp;&nbsp;&nbsp; inline QGlobalStatic(T *p) : pointer(p) { }<br />&nbsp;&nbsp;&nbsp; inline ~QGlobalStatic() { pointer = 0; }<br />};<br /><br />#define Q_GLOBAL_STATIC(TYPE, NAME)&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; \<br />&nbsp;&nbsp;&nbsp; static TYPE *NAME()&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; \<br />&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static TYPE this_##NAME;&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; \<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static QGlobalStatic&lt;TYPE &gt; global_##NAME(&amp;this_##NAME); \<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return global_##NAME.pointer;&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; \<br />&nbsp;&nbsp;&nbsp; }<br /><br /></td></tr></tbody></table><span style="color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 24.545454025268555px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;</span><br style="line-height: 24.545454025268555px; color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ffffff;" /><br style="line-height: 24.545454025268555px; color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ffffff;" /><span style="color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 24.545454025268555px; background-color: #ffffff;">上面的展开成</span><br style="line-height: 24.545454025268555px; color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ffffff;" /><table border="1" cellpadding="1" cellspacing="1" height="120" width="616" style="line-height: 24.545454025268555px; color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 13.63636302947998px; background-color: #ffffff;"><tbody><tr><td>&nbsp;static&nbsp; QFontDatabasePrivate *privateDb()<br />{<br />&nbsp;&nbsp;&nbsp; static QFontDatabasePrivate this_privateDb;&nbsp; // 注意第一次引用的时候会开始进行初始化, 以后不再生成<br />&nbsp;&nbsp; static QGLobalStatic&lt;QFontDatabasePrivate&gt; global_privateDb(&amp;this_privateDb); //对上面生成的对象的指针进行包装， 同上，只有第一次才会生成<br /><br />&nbsp; return global_privateDb;<br />}<br /></td></tr></tbody></table><p style="line-height: 24.545454025268555px; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ffffff;">QFontDatabase的构造函数中会调用createDatabase （里面调用了initializeDb), initializeDb里调用了privateDb(),一个这个时候是第一次调用， 会生成QFontDatabasePrivate对象</p><p style="line-height: 24.545454025268555px; margin: 0px 0px 10px; padding: 0px; color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ffffff;">QFontDatabasePrivate中的QDataStream *stream成员才是真正处理qte的字体</p><img src ="http://www.cppblog.com/biao/aggbug/201312.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-06-26 10:02 <a href="http://www.cppblog.com/biao/archive/2013/06/26/201312.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++：QT插件开发方式</title><link>http://www.cppblog.com/biao/archive/2013/06/25/201308.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 25 Jun 2013 15:26:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/06/25/201308.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/201308.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/06/25/201308.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/201308.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/201308.html</trackback:ping><description><![CDATA[From:&nbsp;http://blog.csdn.net/henreash/article/details/7264489@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">创建一个QT的库项目,删除自动生成的.h和.cpp文件,添加一个接口定义.h文件和一个接口实现类(一个.h一个.cpp).代码如下:</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">1.接口文件源码</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#ifndef PLUGININTERFACE_H<br />
#define PLUGININTERFACE_H</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#include &lt;QString&gt;</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><br />
class EchoInterface<br />
{<br />
public:<br />
&nbsp;virtual ~EchoInterface() {}<br />
&nbsp;virtual QString echo(const QString &amp;message) = 0;<br />
};</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">QT_BEGIN_NAMESPACE<br />
Q_DECLARE_INTERFACE(EchoInterface, "com.hollysys.plugin.EchoIntrface/1.0");<br />
QT_END_NAMESPACE</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><br />
#endif</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">2.接口实现类头文件</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#ifndef PLUGIN_H<br />
#define PLUGIN_H</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">//#include "plugin_global.h"<br />
#include &lt;QObject&gt;<br />
#include "plugininterface.h"</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">class Plugin : public QObject, EchoInterface<br />
{<br />
&nbsp;Q_OBJECT<br />
&nbsp;Q_INTERFACES(EchoInterface)<br />
public:<br />
&nbsp;Plugin();<br />
&nbsp;~Plugin();<br />
public:<br />
&nbsp;QString echo(const QString &amp;message);</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><br />
};</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#endif // PLUGIN_H</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">3.接口实现类cpp文件</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#include "plugin.h"<br />
#include &lt;QtGui&gt;</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><br />
Plugin::Plugin()<br />
{</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">}</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">Plugin::~Plugin()<br />
{</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">}</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">QString Plugin::echo(const QString &amp;message)<br />
{<br />
&nbsp;return message;<br />
}</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">Q_EXPORT_PLUGIN2("echoPlugin", Plugin);<br />
</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">编译生成dll格式的插件.这里可能会遇到LNK2001错误,因为插件接口定义依赖于QT的元数据,而在代码中手动添加Q_OBJECT宏后,编译器不会自动为我们生成moc_XXXX.cpp文件,因此需要使用命令行生成moc元数据文件:cmd--&gt;cd 源码所在命令 --&gt;moc -o moc_XXXX.cpp XXXX.h.这样就可以手动创建出moc元数据文件,解决LNK2001编译错误.</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">建立一个GUI测试项目,代码如下:</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#include "test.h"<br />
#include &lt;QtGui&gt;<br />
#include &lt;QMessageBox&gt;<br />
#include &lt;QDir&gt;</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">Test::Test(QWidget *parent, Qt::WFlags flags)<br />
&nbsp;: QMainWindow(parent, flags)<br />
{<br />
&nbsp;ui.setupUi(this);<br />
&nbsp;QObject::connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(ButtonClicked()));<br />
&nbsp;loadPlugin();<br />
}</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">Test::~Test()<br />
{</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">}</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">bool Test::loadPlugin()<br />
{<br />
&nbsp;QDir pluginsDir(qApp-&gt;applicationDirPath());<br />
&nbsp;foreach (QString filename, pluginsDir.entryList(QDir::Files))<br />
&nbsp;{<br />
&nbsp;&nbsp;QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(filename));<br />
&nbsp;&nbsp;QObject *plugin = pluginLoader.instance();<br />
&nbsp;&nbsp;if(plugin)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;echoInterface = qobject_cast&lt;EchoInterface *&gt;(plugin);//echoInterface是成员变量<br />
&nbsp;&nbsp;&nbsp;if(echoInterface)<br />
&nbsp;&nbsp;&nbsp;&nbsp;return true;<br />
&nbsp;&nbsp;}<br />
&nbsp;}<br />
}</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">void Test::ButtonClicked()<br />
{<br />
&nbsp;QString plugin = ui.lineEdit-&gt;text();<br />
&nbsp;QMessageBox::information(NULL, "", echoInterface-&gt;echo(plugin));<br />
}</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">分析代码可见,这里对所有与exe文件同目录的文件尝试加载插件,如果加载成功则返回.代码实现非常简洁.在正式开发中可将已加载的插件接口存放在列表中,在需要的时候依次调用即可.</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">另外如果想获取插件中类定义的元数据,可以使插件接口类从QObject继承,并使用Q_CLASSINFO宏添加键值对,如Q_CLASSINFO("Author**", "Henreash**").并从主程序中使用插件对象元数据获取这些键值对:</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">&nbsp;const QMetaObject *mo = echoInterface-&gt;metaObject();<br />
&nbsp;for(int i = 0; i &lt; mo-&gt;classInfoCount(); i++)<br />
&nbsp;{<br />
&nbsp;&nbsp;qDebug() &lt;&lt; mo-&gt;classInfo(i).name() &lt;&lt; mo-&gt;classInfo(i).value();<br />
&nbsp;}</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">使用这个机制可以在定义插件类的时候向主程序传递一些特殊信息.</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">测试发现,如果在插件接口类中定义一个静态变量,那么这个静态变量在插件中的地址和在主程序中的地址是不相同的.</p>
</div><img src ="http://www.cppblog.com/biao/aggbug/201308.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-06-25 23:26 <a href="http://www.cppblog.com/biao/archive/2013/06/25/201308.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++：单例 Singleton</title><link>http://www.cppblog.com/biao/archive/2013/06/25/201306.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 25 Jun 2013 13:46:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/06/25/201306.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/201306.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/06/25/201306.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/201306.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/201306.html</trackback:ping><description><![CDATA[<p style="margin: 0.4em 0px 0.5em; line-height: 22px; font-family: sans-serif; font-size: 15px; background-color: #ffffff; ">From:&nbsp;http://zh.wikipedia.org/wiki/单例模式</p>
<p style="margin: 0.4em 0px 0.5em; line-height: 22px; font-family: sans-serif; font-size: 15px; background-color: #ffffff; ">在<a href="http://zh.wikipedia.org/wiki/C%2B%2B" title="C++" style="text-decoration: none; color: #0b0080; background-image: none; background-position: initial initial; background-repeat: initial initial; ">C++</a>编程语言中，单例模式应用的例子如下述代码所示（这里仅仅提供一个示例，这个例子对多线程的情况并不是安全的）：</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr" style="direction: ltr; font-family: monospace, Courier; padding: 1em; border-left-color: #2f6fab; background-color: #f9f9f9; line-height: 1.1em; font-size: 15px; ">
<div class="cpp source-cpp" style="line-height: normal; font-family: monospace; ">
<pre class="de1" style="font-family: monospace, monospace; padding: 0px; border: 0px none white; line-height: 1.2em; font-size: 1em; margin-top: 0px; margin-bottom: 0px; background-image: none; vertical-align: top; "><span class="co1" style="color: #666666; ">// ...</span>
<span class="kw2" style="color: #0000ff; ">class</span> lock
<span class="br0" style="color: #008000; ">{</span>
<span class="kw2" style="color: #0000ff; ">public</span><span class="sy4" style="color: #008080; ">:</span>
lock<span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
lock<span class="br0" style="color: #008000; ">(</span>lock <span class="kw4" style="color: #0000ff; ">const</span> <span class="sy3" style="color: #000040; ">&amp;</span> l<span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
~lock<span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
lock <span class="sy3" style="color: #000040; ">&amp;</span> operator <span class="sy1" style="color: #000080; ">=</span><span class="br0" style="color: #008000; ">(</span>lock <span class="kw4" style="color: #0000ff; ">const</span> <span class="sy3" style="color: #000040; ">&amp;</span> l<span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw4" style="color: #0000ff; ">void</span> request<span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw4" style="color: #0000ff; ">void</span> release<span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="co1" style="color: #666666; ">// ...</span>
<span class="br0" style="color: #008000; ">}</span><span class="sy4" style="color: #008080; ">;</span>
lock<span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">lock</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
<span class="co1" style="color: #666666; ">// ...</span>
<span class="br0" style="color: #008000; ">}</span>
<span class="co1" style="color: #666666; ">// ...</span>
lock<span class="sy4" style="color: #008080; ">::</span>~lock<span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
<span class="co1" style="color: #666666; ">// ...</span>
<span class="br0" style="color: #008000; ">}</span>
<span class="co1" style="color: #666666; ">// ...</span>
<span class="kw4" style="color: #0000ff; ">void</span> lock<span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">request</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
<span class="co1" style="color: #666666; ">// ...</span>
<span class="br0" style="color: #008000; ">}</span>
<span class="kw4" style="color: #0000ff; ">void</span> lock<span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">release</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
<span class="co1" style="color: #666666; ">// ...</span>
<span class="br0" style="color: #008000; ">}</span>
<span class="co1" style="color: #666666; ">// ...</span>
<span class="co1" style="color: #666666; ">// assumes _DATA_TYPE_ has a default constructor</span>
<span class="kw2" style="color: #0000ff; ">template</span><span class="sy1" style="color: #000080; ">&lt;</span><span class="kw2" style="color: #0000ff; ">typename</span> _DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span>
<span class="kw2" style="color: #0000ff; ">class</span> singleton
<span class="br0" style="color: #008000; ">{</span>
<span class="kw2" style="color: #0000ff; ">public</span><span class="sy4" style="color: #008080; ">:</span>
<span class="kw4" style="color: #0000ff; ">static</span> _DATA_TYPE_ <span class="sy2" style="color: #000040; ">*</span> request<span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw4" style="color: #0000ff; ">static</span> <span class="kw4" style="color: #0000ff; ">void</span> release<span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw2" style="color: #0000ff; ">private</span><span class="sy4" style="color: #008080; ">:</span>
singleton<span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
singleton<span class="br0" style="color: #008000; ">(</span>singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span> <span class="kw4" style="color: #0000ff; ">const</span> <span class="sy3" style="color: #000040; ">&amp;</span> s<span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
~singleton<span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span> <span class="sy3" style="color: #000040; ">&amp;</span> operator <span class="sy1" style="color: #000080; ">=</span><span class="br0" style="color: #008000; ">(</span>singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span> <span class="kw4" style="color: #0000ff; ">const</span> <span class="sy3" style="color: #000040; ">&amp;</span> s<span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw4" style="color: #0000ff; ">static</span> _DATA_TYPE_ <span class="sy2" style="color: #000040; ">*</span> pointer<span class="sy4" style="color: #008080; ">;</span>
<span class="kw4" style="color: #0000ff; ">static</span> lock mutex<span class="sy4" style="color: #008080; ">;</span>
<span class="co1" style="color: #666666; ">// ...</span>
<span class="br0" style="color: #008000; ">}</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw2" style="color: #0000ff; ">template</span><span class="sy1" style="color: #000080; ">&lt;</span><span class="kw2" style="color: #0000ff; ">typename</span> _DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span>
_DATA_TYPE_ <span class="sy2" style="color: #000040; ">*</span> singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">pointer</span> <span class="sy1" style="color: #000080; ">=</span> <span class="nu0" style="color: #0000dd; ">0</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw2" style="color: #0000ff; ">template</span><span class="sy1" style="color: #000080; ">&lt;</span><span class="kw2" style="color: #0000ff; ">typename</span> _DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span>
lock singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">mutex</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw2" style="color: #0000ff; ">template</span><span class="sy1" style="color: #000080; ">&lt;</span><span class="kw2" style="color: #0000ff; ">typename</span> _DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span>
_DATA_TYPE_ <span class="sy2" style="color: #000040; ">*</span> singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">request</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
<span class="kw1" style="color: #0000ff; ">if</span><span class="br0" style="color: #008000; ">(</span>singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">pointer</span> <span class="sy1" style="color: #000080; ">==</span> <span class="nu0" style="color: #0000dd; ">0</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">mutex</span>.<span class="me1" style="color: #007788; ">request</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw1" style="color: #0000ff; ">if</span><span class="br0" style="color: #008000; ">(</span>singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">pointer</span> <span class="sy1" style="color: #000080; ">==</span> <span class="nu0" style="color: #0000dd; ">0</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">pointer</span> <span class="sy1" style="color: #000080; ">=</span> <span class="kw3" style="color: #0000dd; ">new</span> _DATA_TYPE_<span class="sy4" style="color: #008080; ">;</span>
<span class="br0" style="color: #008000; ">}</span>
singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">mutex</span>.<span class="me1" style="color: #007788; ">release</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="br0" style="color: #008000; ">}</span>
<span class="kw1" style="color: #0000ff; ">return</span> singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">pointer</span><span class="sy4" style="color: #008080; ">;</span>
<span class="br0" style="color: #008000; ">}</span>
<span class="kw2" style="color: #0000ff; ">template</span><span class="sy1" style="color: #000080; ">&lt;</span><span class="kw2" style="color: #0000ff; ">typename</span> _DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span>
<span class="kw4" style="color: #0000ff; ">void</span> singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">release</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
<span class="kw1" style="color: #0000ff; ">if</span><span class="br0" style="color: #008000; ">(</span>singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">pointer</span> <span class="sy3" style="color: #000040; ">!</span><span class="sy1" style="color: #000080; ">=</span> <span class="nu0" style="color: #0000dd; ">0</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">mutex</span>.<span class="me1" style="color: #007788; ">request</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw1" style="color: #0000ff; ">if</span><span class="br0" style="color: #008000; ">(</span>singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">pointer</span> <span class="sy3" style="color: #000040; ">!</span><span class="sy1" style="color: #000080; ">=</span> <span class="nu0" style="color: #0000dd; ">0</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
<span class="kw3" style="color: #0000dd; ">delete</span> singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">pointer</span><span class="sy4" style="color: #008080; ">;</span>
singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">pointer</span> <span class="sy1" style="color: #000080; ">=</span> <span class="nu0" style="color: #0000dd; ">0</span><span class="sy4" style="color: #008080; ">;</span>
<span class="br0" style="color: #008000; ">}</span>
singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">mutex</span>.<span class="me1" style="color: #007788; ">release</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="br0" style="color: #008000; ">}</span>
<span class="br0" style="color: #008000; ">}</span>
<span class="kw2" style="color: #0000ff; ">template</span><span class="sy1" style="color: #000080; ">&lt;</span><span class="kw2" style="color: #0000ff; ">typename</span> _DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span>
singleton<span class="sy1" style="color: #000080; ">&lt;</span>_DATA_TYPE_<span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">singleton</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
<span class="co1" style="color: #666666; ">// ...</span>
<span class="br0" style="color: #008000; ">}</span>
<span class="co1" style="color: #666666; ">// ...</span>
<span class="kw4" style="color: #0000ff; ">int</span> main<span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span>
<span class="br0" style="color: #008000; ">{</span>
<span class="kw4" style="color: #0000ff; ">int</span> <span class="sy2" style="color: #000040; ">*</span> s<span class="sy4" style="color: #008080; ">;</span>
s <span class="sy1" style="color: #000080; ">=</span> singleton<span class="sy1" style="color: #000080; ">&lt;</span><span class="kw4" style="color: #0000ff; ">int</span><span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">request</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="co1" style="color: #666666; ">// ...</span>
singleton<span class="sy1" style="color: #000080; ">&lt;</span><span class="kw4" style="color: #0000ff; ">int</span><span class="sy1" style="color: #000080; ">&gt;</span><span class="sy4" style="color: #008080; ">::</span><span class="me2" style="color: #007788; ">release</span><span class="br0" style="color: #008000; ">(</span><span class="br0" style="color: #008000; ">)</span><span class="sy4" style="color: #008080; ">;</span>
<span class="kw1" style="color: #0000ff; ">return</span> <span class="nu0" style="color: #0000dd; ">0</span><span class="sy4" style="color: #008080; ">;</span>
<span class="br0" style="color: #008000; ">}</span>
</pre>
<div><span class="br0" style="color: #008000; "><br />
</span></div>
</div>
</div>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/201306.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-06-25 21:46 <a href="http://www.cppblog.com/biao/archive/2013/06/25/201306.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：展示OpenGL特性的软件Tutors</title><link>http://www.cppblog.com/biao/archive/2013/04/19/199557.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 18 Apr 2013 16:24:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/04/19/199557.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/199557.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/04/19/199557.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/199557.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/199557.html</trackback:ping><description><![CDATA[<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/naterobins.jpg" alt="nate robins" width="600" height="80" border="0" vspace="0" hspace="0" /></td>
        </tr>
    </tbody>
</table>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/menu-left.jpg" alt="" width="20" height="30" border="0" vspace="0" hspace="0" /></td>
            <td><a href="http://user.xmission.com/~nate/index.html"><img src="http://user.xmission.com/~nate/pics/main-dim.jpg" alt="main" width="80" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><a href="http://user.xmission.com/~nate/opengl.html"><img src="http://user.xmission.com/~nate/pics/opengl-lit.jpg" alt="OPENGL" width="145" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><a href="http://user.xmission.com/~nate/chronicles.html"><img src="http://user.xmission.com/~nate/pics/chronicles-dim.jpg" alt="chronicles" width="215" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><a href="http://user.xmission.com/~nate/allies.html"><img src="http://user.xmission.com/~nate/pics/allies-dim.jpg" alt="allies" width="120" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><img src="http://user.xmission.com/~nate/pics/menu-right.jpg" alt="" width="20" height="30" border="0" vspace="0" hspace="0" /></td>
        </tr>
    </tbody>
</table>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/up-left.jpg" alt="---" width="300" height="50" border="0" vspace="0" hspace="0" /></td>
            <td align="center" valign="bottom" width="200"><em>Tutors</em></td>
            <td><img src="http://user.xmission.com/~nate/pics/up-right.jpg" alt="---" width="100" height="50" border="0" vspace="0" hspace="0" /></td>
        </tr>
    </tbody>
</table>
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<table width="550" border="0" cellpadding="0" cellspacing="20" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td align="center"><a href="http://user.xmission.com/~nate/tutors/tutors-src.zip">Tutors source code package (tutors-src.zip 920KB)</a>&nbsp;<br />
            <br />
            <a href="http://user.xmission.com/~nate/tutors/tutors-win32.zip">Source package + Windows executables (tutors-win32.zip 1.24MB)</a>&nbsp;<br />
            <br />
            <a href="http://user.xmission.com/~nate/tutors/tutors-macosx.zip">Source package + Mac OS X universal binaries (tutors-macosx.zip 1.2MB)</a>&nbsp;<br />
            <br />
            <a href="http://user.xmission.com/~nate/tutors-contrib.html">Contributions</a>&nbsp;from various people (Unix makefiles, etc).&nbsp;<br />
            <br />
            </td>
        </tr>
        <tr>
            <td>
            <table align="right" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/fog.png"><img src="http://user.xmission.com/~nate/tutors/fog-.png" alt="fog" width="225" height="225" border="1" vspace="0" hspace="5" align="right" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The fog tutorial program (shown at right) demonstrates how to use depth cueing (or fog) in OpenGL. It includes command panels that allow dynamic update of the parameters for linear, exponential and exponential<sup>2</sup>&nbsp;fog functions. The fog color can also be dynamically changed.</td>
        </tr>
        <tr>
            <td>
            <table align="left" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/lightposition.png"><img src="http://user.xmission.com/~nate/tutors/lightposition-.png" alt="lightposition" width="225" height="225" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The lightposition tutorial program (shown at left) demonstrates how lighting position is effected by the viewing transformation. The order in which the light position and the viewing transform are established is configurable, as are the parameters for the position and transform.</td>
        </tr>
        <tr>
            <td>
            <table align="center" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/lightmaterial.png"><img src="http://user.xmission.com/~nate/tutors/lightmaterial-.png" alt="lightmaterial" width="475" height="317" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            <br />
            The lightmaterial tutorial program (shown above) demonstrates how OpenGL lighting and material properties interact and effect each other. All material &amp; light properties are tweakable. A second command panel allows spotlight parameters &amp; attenuation factors to be changed.</td>
        </tr>
        <tr>
            <td>
            <table align="right" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/projection.png"><img src="http://user.xmission.com/~nate/tutors/projection-.png" alt="projection" width="225" height="225" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The projection tutorial program (shown at right) demonstrates how the many types of projection transformations work. A command panel is included for gluPerspective(), glOrtho() and glFrustum(). In addition, the viewing transform can be modified via the gluLookat() function.</td>
        </tr>
        <tr>
            <td>
            <table align="left" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/transformation.png"><img src="http://user.xmission.com/~nate/tutors/transformation-.png" alt="transformation" width="225" height="225" border="1" vspace="0" hspace="5" align="left" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The transformation tutorial program (shown at left) demonstrates how the basic transformations of rotate, translate and scale operate in OpenGL. The order of the transforms can be changed to see how that effects rendering.</td>
        </tr>
        <tr>
            <td>
            <table align="center" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/texture.png"><img src="http://user.xmission.com/~nate/tutors/texture-.png" alt="texture" width="475" height="317" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            <br />
            The texture tutorial program (shown above) demonstrates how OpenGL texturing works. Specifically, the texture coordinates for a polygon are provided for manipulation as are the polygons coordinates themselves. The texture parameter &amp; environment attributes are tweakable. A separate command panel allows manipulation of the texture matrix.</td>
        </tr>
        <tr>
            <td>
            <table align="right" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/shapes.png"><img src="http://user.xmission.com/~nate/tutors/shapes-.png" alt="shapes" width="263" height="225" border="1" vspace="0" hspace="5" align="right" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The shapes tutorial program (shown at right) demonstrates how the many types of primitives work. A command panel for each primitive type is included. This tutorial was written by Mason Woo (<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#109;&#97;&#115;&#111;&#110;&#64;&#119;&#111;&#111;&#46;&#99;&#111;&#109;">mason@woo.com</a>).</td>
        </tr>
    </tbody>
</table>
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td align="center"><a href="http://www.digits.com/web_counter"><img src="http://counter.digits.com/wc/-d/8/-r/-z/-c/26/-f/aaaaaa/-b/ffffff/opengl_tutors" border="0"  alt="" /></a></td>
        </tr>
    </tbody>
</table>
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/dn-left.jpg" alt="---" width="100" height="50" border="0" vspace="0" hspace="0" /></td>
            <td><img src="http://user.xmission.com/~nate/pics/dn-middle.jpg" alt="---" width="200" height="50" border="0" vspace="0" hspace="0" /></td>
            <td><img src="http://user.xmission.com/~nate/pics/dn-right.jpg" alt="---" width="300" height="50" border="0" vspace="0" hspace="0" /><br />
            <br />
            </td>
        </tr>
    </tbody>
</table>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/199557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-04-19 00:24 <a href="http://www.cppblog.com/biao/archive/2013/04/19/199557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++：LIB和DLL的区别与使用</title><link>http://www.cppblog.com/biao/archive/2013/03/14/198416.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 14 Mar 2013 06:38:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/03/14/198416.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/198416.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/03/14/198416.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/198416.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/198416.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 14px; color: #303030; font-family: Verdana, Helvetica, Arial; font-size: 12px; line-height: 18px; text-align: justify; background-color: #ffffff;"><span style="font-family: Courier;">共有两种库：</span><br /><span style="font-family: Courier; color: #ff0000;">一种是LIB包含了函数所在的DLL文件和文件中函数位置的信息（入口），代码由运行时加载在进程空间中的DLL提供，称为动态链接库dynamic link library。</span><br /><span style="font-family: Courier; color: #ff0000;">一种是LIB包含函数代码本身，在编译时直接将代码加入程序当中，称为静态链接库static link library。</span><br /><span style="font-family: Courier;">共有两种链接方式：</span><br /><span style="font-family: Courier;">动态链接使用动态链接库，允许可执行模块（.dll文件或.exe文件）仅包含在运行时定位DLL函数的可执行代码所需的信息。</span><br /><span style="font-family: Courier;">静态链接使用静态链接库，链接器从静态链接库LIB获取所有被引用函数，并将库同代码一起放到可执行文件中。</span><br /><br /><span style="font-family: Courier;">关于lib和dll的区别如下：</span><br /><span style="font-family: Courier;">（1）lib是编译时用到的，dll是运行时用到的。如果要完成源代码的编译，只需要lib；如果要使动态链接的程序运行起来，只需要dll。</span><br /><span style="font-family: Courier;">（2）如果有dll文件，那么lib一般是一些索引信息，记录了dll中函数的入口和位置，dll中是函数的具体内容；如果只有lib文件，那么这个lib文件是静态编译出来的，索引和实现都在其中。使用静态编译的lib文件，在运行程序时不需要再挂动态库，缺点是导致应用程序比较大，而且失去了动态库的灵活性，发布新版本时要发布新的应用程序才行。</span><br /><span style="font-family: Courier;">（3）动态链接的情况下，有两个文件：一个是LIB文件，一个是DLL文件。LIB包含被DLL导出的函数名称和位置，DLL包含实际的函数和数据，应用程序使用LIB文件链接到DLL文件。在应用程序的可执行文件中，存放的不是被调用的函数代码，而是DLL中相应函数代码的地址，从而节省了内存资源。DLL和LIB文件必须随应用程序一起发行，否则应用程序会产生错误。如果不想用lib文件或者没有lib文件，可以用WIN32 API函数LoadLibrary、GetProcAddress装载。</span><br /><br /><span style="font-family: Courier;">使用lib需注意两个文件：</span><br /><span style="font-family: Courier;">（1）.h头文件，包含lib中说明输出的类或符号原型或数据结构。应用程序调用lib时，需要将该文件包含入应用程序的源文件中。</span><br /><span style="font-family: Courier;">（2）.LIB文件，略。</span><br /><br /><span style="font-family: Courier;">使用dll需注意三个文件：</span><br /><span style="font-family: Courier;">（1）.h头文件，包含dll中说明输出的类或符号原型或数据结构的.h文件。应用程序调用dll时，需要将该文件包含入应用程序的源文件中。</span><br /><span style="font-family: Courier;">（2）.LIB文件，是dll在编译、链接成功之后生成的文件，作用是当其他应用程序调用dll时，需要将该文件引入应用程序，否则产生错误。</span><span style="color: red; font-family: Courier;">如果不想用lib文件或者没有lib文件，可以用WIN32 API函数LoadLibrary、GetProcAddress装载。<br /></span><span style="font-family: Courier;">（3）.dll文件，真正的可执行文件，开发成功后的应用程序在发布时，只需要有.exe文件和.dll文件，并不需要.lib文件和.h头文件。</span><br /><br /><span style="font-family: Courier;">使用lib的方法：</span><br /><span style="font-family: Courier;">静态lib中，一个lib文件实际上是任意个obj文件的集合，obj文件是cpp文件编译生成的。在编译这种静态库工程时，根本不会遇到链接错误；即使有错，也只会在使用这个lib的EXT文件或者DLL工程里暴露出来。</span><br /><span style="font-family: Courier;">在VC中新建一个static library类型的工程Lib，加入test.cpp文件和test.h文件（头文件内包括函数声明），然后编译，就生成了Lib.lib文件。</span><br /><span style="font-family: Courier;">别的工程要使用这个lib有两种方式：</span><br /><span style="font-family: Courier;">（1）在project-&gt;link-&gt;Object/Library Module中加入Lib.lib文件（先查询工程目录，再查询系统Lib目录）；或者在源代码中加入指令#pragma comment(lib, &#8220;Lib.lib&#8221;)。</span><br /><span style="font-family: Courier;">（2）将Lib.lib拷入工程所在目录，或者执行文件生成的目录，或者系统Lib目录中。</span><br /><span style="font-family: Courier;">（3）加入相应的头文件test.h。</span><br /><br /><span style="font-family: Courier;">使用DLL的方法：</span><br /><span style="font-family: Courier;">使用动态链接中的lib，不是obj文件的集合，即里面不会有实际的实现，它只是提供动态链接到DLL所需要的信息，这种lib可以在编译一个DLL工程时由编译器生成。</span><br /><span style="font-family: Courier;">创建DLL工程的方法（略）。</span><br /><span style="font-family: Courier; color: #ff0000;"><strong>（1）隐式链接</strong></span><br /><span style="font-family: Courier;">第一种方法是：通过project-&gt;link-&gt;Object/Library Module中加入.lib文件（或者在源代码中加入指令#pragma comment(lib, &#8220;Lib.lib&#8221;)），并将.dll文件置入工程所在目录，然后添加对应的.h头文件。</span></p><div style="font-size: 13px; color: #303030; font-family: Verdana, Helvetica, Arial; line-height: 18px; text-align: justify; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 1061.3333740234375px; word-break: break-all;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><span style="color: #000000; font-family: Courier;">#include&nbsp;</span><span style="color: #000000; font-family: Courier;">"</span><span style="color: #000000; font-family: Courier;">stdafx.h</span><span style="color: #000000; font-family: Courier;">"</span><span style="color: #000000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">#include&nbsp;</span><span style="color: #000000; font-family: Courier;">"</span><span style="color: #000000; font-family: Courier;">DLLSample.h</span><span style="color: #000000; font-family: Courier;">"</span><span style="color: #000000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">#pragma&nbsp;comment(lib,&nbsp;</span><span style="color: #000000; font-family: Courier;">"</span><span style="color: #000000; font-family: Courier;">DLLSample.lib</span><span style="color: #000000; font-family: Courier;">"</span><span style="color: #000000; font-family: Courier;">)&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; font-family: Courier;">//</span><span style="color: #008000; font-family: Courier;">你也可以在项目属性中设置库的链接</span><span style="color: #008000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span><span style="color: #000000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span><span style="color: #0000ff; font-family: Courier;">int</span><span style="color: #000000; font-family: Courier;">&nbsp;main()<br /><img id="Codehighlighter1_116_187_Open_Image" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" alt="" style="border: 0px;" /></span><span id="Codehighlighter1_116_187_Open_Text"><span style="color: #000000; font-family: Courier;">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TestDLL(</span><span style="color: #000000; font-family: Courier;">123</span><span style="color: #000000; font-family: Courier;">);&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; font-family: Courier;">//</span><span style="color: #008000; font-family: Courier;">dll中的函数，在DllSample.h中声明</span><span style="color: #008000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier;">return</span><span style="color: #000000; font-family: Courier;">(</span><span style="color: #000000; font-family: Courier;">1</span><span style="color: #000000; font-family: Courier;">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">}</span></span><span style="color: #000000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span></div><p style="margin: 0px 0px 14px; color: #303030; font-family: Verdana, Helvetica, Arial; font-size: 12px; line-height: 18px; text-align: justify; background-color: #ffffff;"><span style="font-family: Courier; color: #ff0000;"><strong>（2）显式链接</strong></span><br /><span style="font-family: Courier;">需要函数指针和WIN32 API函数LoadLibrary、GetProcAddress装载，使用这种载入方法，</span><span style="color: red; font-family: Courier;">不需要.lib文件和.h头文件，只需要.dll文件即可</span><span style="font-family: Courier;">（将.dll文件置入工程目录中）。</span></p><div style="font-size: 13px; color: #303030; font-family: Verdana, Helvetica, Arial; line-height: 18px; text-align: justify; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 1061.3333740234375px; word-break: break-all;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><span style="color: #000000; font-family: Courier;">#include&nbsp;</span><span style="color: #000000; font-family: Courier;">&lt;</span><span style="color: #000000; font-family: Courier;">iostream</span><span style="color: #000000; font-family: Courier;">&gt;</span><span style="color: #000000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">#include&nbsp;</span><span style="color: #000000; font-family: Courier;">&lt;</span><span style="color: #000000; font-family: Courier;">windows.h</span><span style="color: #000000; font-family: Courier;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; font-family: Courier;">//</span><span style="color: #008000; font-family: Courier;">使用函数和某些特殊变量</span><span style="color: #008000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">typedef&nbsp;</span><span style="color: #0000ff; font-family: Courier;">void</span><span style="color: #000000; font-family: Courier;">&nbsp;(</span><span style="color: #000000; font-family: Courier;">*</span><span style="color: #000000; font-family: Courier;">DLLFunc)(</span><span style="color: #0000ff; font-family: Courier;">int</span><span style="color: #000000; font-family: Courier;">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span><span style="color: #0000ff; font-family: Courier;">int</span><span style="color: #000000; font-family: Courier;">&nbsp;main()<br /><img id="Codehighlighter1_104_540_Open_Image" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" alt="" style="border: 0px;" /></span><span id="Codehighlighter1_104_540_Open_Text"><span style="color: #000000; font-family: Courier;">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DLLFunc&nbsp;dllFunc;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HINSTANCE&nbsp;hInstLibrary&nbsp;</span><span style="color: #000000; font-family: Courier;">=</span><span style="color: #000000; font-family: Courier;">&nbsp;LoadLibrary(</span><span style="color: #000000; font-family: Courier;">"</span><span style="color: #000000; font-family: Courier;">DLLSample.dll</span><span style="color: #000000; font-family: Courier;">"</span><span style="color: #000000; font-family: Courier;">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier;">if</span><span style="color: #000000; font-family: Courier;">&nbsp;(hInstLibrary&nbsp;</span><span style="color: #000000; font-family: Courier;">==</span><span style="color: #000000; font-family: Courier;">&nbsp;NULL)<br /><img id="Codehighlighter1_237_284_Open_Image" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_237_284_Open_Text"><span style="color: #000000; font-family: Courier;">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FreeLibrary(hInstLibrary);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dllFunc&nbsp;</span><span style="color: #000000; font-family: Courier;">=</span><span style="color: #000000; font-family: Courier;">&nbsp;(DLLFunc)GetProcAddress(hInstLibrary,&nbsp;</span><span style="color: #000000; font-family: Courier;">"</span><span style="color: #000000; font-family: Courier;">TestDLL</span><span style="color: #000000; font-family: Courier;">"</span><span style="color: #000000; font-family: Courier;">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier;">if</span><span style="color: #000000; font-family: Courier;">&nbsp;(dllFunc&nbsp;</span><span style="color: #000000; font-family: Courier;">==</span><span style="color: #000000; font-family: Courier;">&nbsp;NULL)<br /><img id="Codehighlighter1_391_438_Open_Image" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_391_438_Open_Text"><span style="color: #000000; font-family: Courier;">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FreeLibrary(hInstLibrary);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dllFunc(</span><span style="color: #000000; font-family: Courier;">123</span><span style="color: #000000; font-family: Courier;">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cin.</span><span style="color: #0000ff; font-family: Courier;">get</span><span style="color: #000000; font-family: Courier;">();<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FreeLibrary(hInstLibrary);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier;">return</span><span style="color: #000000; font-family: Courier;">(</span><span style="color: #000000; font-family: Courier;">1</span><span style="color: #000000; font-family: Courier;">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" style="border: 0px;" /></span><span style="color: #000000; font-family: Courier;">}</span></span><span style="color: #000000;"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span></div><p style="margin: 0px 0px 14px; color: #303030; font-family: Verdana, Helvetica, Arial; font-size: 12px; line-height: 18px; text-align: justify; background-color: #ffffff;"><span style="font-family: Courier;">LoadLibrary函数利用一个名称作为参数，获得DLL的实例（HINSTANCE类型是实例的句柄），通常调用该函数后需要查看一下函数返回是否成功，如果不成功则返回NULL（句柄无效），此时调用函数FreeLibrary释放DLL获得的内存。</span><br /><span style="font-family: Courier;">GetProcAddress函数利用DLL的句柄和函数的名称作为参数，返回相应的函数指针，同时必须使用强转；判断函数指针是否为NULL，如果是则调用函数FreeLibrary释放DLL获得的内存。此后，可以使用函数指针来调用实际的函数。</span><br /><span style="font-family: Courier;">最后要记得使用FreeLibrary函数释放内存。</span><br /><br /><span style="color: red; font-family: Courier;">注意：应用程序如何找到DLL文件？</span><br /><span style="font-family: Courier;">使用LoadLibrary显式链接，那么在函数的参数中可以指定DLL文件的完整路径；如果不指定路径，或者进行隐式链接，Windows将遵循下面的搜索顺序来定位DLL：</span><br /><span style="font-family: Courier;">（1）包含EXE文件的目录</span><br /><span style="font-family: Courier;">（2）工程目录</span><br /><span style="font-family: Courier;">（3）Windows系统目录</span><br /><span style="font-family: Courier;">（4）Windows目录</span><br /><span style="font-family: Courier;">（5）列在Path环境变量中的一系列目录</span><br /><br /><span style="font-family: Courier;">From:&nbsp;</span><a href="http://www.cppblog.com/ming81/archive/2013/03/04/198215.html"><span style="font-family: Courier;">http://www.cppblog.com/ming81/archive/2013/03/04/198215.html</span></a><br /><br /></p><p style="margin: 10px 0px; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 20px;"><span style="color: red; font-family: Courier;">.h头文件是编译时必须的，lib是链接时需要的，dll是运行时需要的。</span></p><p style="margin: 10px 0px; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 20px;"><span style="color: red; font-family: Courier;">附加依赖项的是.lib不是.dll，若生成了DLL,则肯定也生成 LIB文件。如果要完成源代码的编译和链接，有头文件和lib就够了。如果也使动态连接的程序运行起来，有dll就够了。在开发和调试阶段，当然最好都有。</span></p><p style="margin: 10px 0px; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 20px;"><span style="font-family: Courier;">.h .lib .dll三者的关系是：</span></p><p style="margin: 10px 0px; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 20px;"><span style="font-family: Courier;">H文件作用是:声明函数接口&nbsp;</span></p><p style="margin: 10px 0px; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 20px;"><span style="font-family: Courier;">DLL文件作用是: 函数可执行代码&nbsp;</span></p><p style="margin: 10px 0px; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 20px;"><span style="font-family: Courier;">当我们在自己的程序中引用了一个H文件里的函数,编链器怎么知道该调用哪个DLL文件呢?这就是LIB文件的作用: 告诉链接器 调用的函数在哪个DLL中，函数执行代码在DLL中的什么位置 ，这也就是为什么需要附加依赖项 .LIB文件，它起到桥梁的作用。如果生成静态库文件，则没有DLL ，只有lib，这时函数可执行代码部分也在lib文件中</span></p><p style="margin: 10px 0px; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 20px;"><span style="font-family: Courier;">目前以lib后缀的库有两种，一种为静态链接库(Static Libary，以下简称&#8220;静态库&#8221;)，另一种为动态连接库(DLL，以下简称&#8220;动态库&#8221;)的导入库(Import Libary，以下简称&#8220;导入库&#8221;）。静态库是一个或者多个obj文件的打包 ，所以有人干脆把从obj文件生成lib的过程称为Archive，即合并到一起。比如你链接一个静态库，如果其中有错，它会准确的找到是哪个obj有错，即静态lib只是壳子。动态库一般会有对应的导入库，方便程序静态载入动态链接库 ，否则你可能就需要自己LoadLibary调入DLL文件，然后再手工GetProcAddress获得对应函数了。有了导入库，你只需要链接导入库后按照头文件函数接口的声明调用函数就可以了。导入库和静态库的区别很大，他们实质是不一样的东西。静态库本身就包含了实际执行代码、符号表等等，而对于导入库而言，其实际的执行代码位于动态库中，导入库只包含了地址符号表等，确保程序找到对应函数的一些基本地址信息。</span></p><p style="margin: 10px 0px; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 20px;"><span style="font-family: Courier;">一般的动态库程序有lib文件和dll文件。lib文件是必须在编译期就连接到应用程序中的，而dll文件是运行期才会被调用的。 如果有dll文件，那么对应的lib文件一般是一些索引信息，具体的实现在dll文件中。如果只有lib文件，那么这个lib文件是静态编译出来的，索引和实现都在其中。静态编译的lib文件有好处：给用户安装时就不需要再挂动态库了。但也有缺点，就是导致应用程序比较大，而且失去了动态库的灵活性，在版本升级时，同时要发布新的应用程序才行。在动态库的情况下，有两个文件，而一个是引入库（.LIB）文件，一个是DLL文件，引入库文件包含被DLL导出的函数的名称和位置，DLL包含实际的函数和数据，应用程序使用LIB文件链接到所需要使用的DLL文件，库中的函数和数据并不复制到可执行文件中，因此在应用程序的可执行文件中，存放的不是被调用的函数代码，而是DLL中所要调用的函数的内存地址，这样当一个或多个应用程序运行是再把程序代码和被调用的函数代码链接起来，从而节省了内存资源。从上面的说明可以看出，DLL和.LIB文件必须随应用程序一起发行，否则应用程序将会产生错误。</span></p><p style="margin: 10px 0px; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 20px;"><span style="font-family: Courier;">静态库和共享库都是一个obj文件的集合 ，但静态链接后，执行程序中存在自己所需obj的一份拷贝，而动态链接后，执行程序仅仅是包含对共享库的一个引用。共享库相当于一个由多个obj文件组合而成的obj文件，在链接后其所有代码被加载，不管需要的还是不需要的。</span><br /><span style="font-family: Courier;">似乎可以得出一个结论：</span><br /><span style="font-family: Courier;">&nbsp; 静态链接后的程序比动态链接的所用存储空间大，因为执行程序中包含了库中代码拷贝；</span><br /><span style="font-family: Courier;">&nbsp; 而动态链接的程序比静态链接的所用的运行空间大，因为它将不需要的代码也加载到运行空间。</span></p><p style="margin: 10px 0px; color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 20px;"><br /><span style="color: red; font-family: Courier;">针对上面的知识2 个问题：<br /><br /></span><span style="color: red; font-family: Courier;">1） DLL和.LIB文件必须随应用程序一起发行，否则应用程序将会产生错误。&nbsp;<br /></span><span style="color: red; font-family: Courier;">我的答案：lib应该不需要吧。<br /><br /></span><span style="color: red; font-family: Courier;">2）如果是某个程序中调用了一个动态库（通过header文件，lib+dll来调用），则对动态库的某个函数的内容修改了，但接口不改，则调用此动态库的程序需重新编译连接吗？如果是通过loadlibary动态加载，需要重新编译连接吗？<br /></span></p><div style="text-align: left;"><span style="color: #c0c0c0; font-family: Courier;">我的答案：通过header+lib+dll调用的话需要重新编译连接，但是通过loadlibrary来使用的话，不需要重新编译连接。</span></div><span style="color: #ff0000; line-height: normal; text-align: start; font-family: Courier;">第2个答案错了 应该是不需要重新编译 接口不变的话 .lib都不用更新<br />From:&nbsp;</span><a href="http://www.cppblog.com/mzty/archive/2010/11/28/134901.html">http://www.cppblog.com/mzty/archive/2010/11/28/134901.html<br /><br /><span style="color: #000000; font-family: 宋体; line-height: 25px; background-color: #ffffff;">&nbsp; &nbsp; 1） 节省内存。同一个软件模块，若是以源代码的形式重用，则会被编译到不同的可执行程序中，同时运行这些exe时这些模块的二进制码会被重复加载到内存中。如 果使用dll,则只在内存中加载一次，所有使用该dll的进程会共享此块内存（当然，像dll中的全局变量这种东西是会被每个进程复制一份的）。</span><br style="margin: 0px; padding: 0px; word-wrap: break-word; color: #000000; font-family: 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #000000; font-family: 宋体; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;</span><br style="margin: 0px; padding: 0px; word-wrap: break-word; color: #000000; font-family: 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #000000; font-family: 宋体; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 2） 不需编译的软件系统升级，若一个软件系统使用了dll,则该dll被改变（函数名不变）时，系统升级只需要更换此dll即可，不需要重新编译整个系统。事实上，很多软件都是以这种方式升级的。例如我们经常玩的星际、魔兽等游戏也是这样进行版本升级的。</span><br style="margin: 0px; padding: 0px; word-wrap: break-word; color: #000000; font-family: 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #000000; font-family: 宋体; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;</span><br style="margin: 0px; padding: 0px; word-wrap: break-word; color: #000000; font-family: 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #000000; font-family: 宋体; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 3） Dll库可以供多种编程语言使用，例如用c编写的dll可以在vb中调用。这一点上DLL还做得很不够，因此在dll的基础上发明了COM技术，更好的解决了一系列问题。</span><br /></a><p>&nbsp;</p><p>&nbsp;</p><img src ="http://www.cppblog.com/biao/aggbug/198416.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-03-14 14:38 <a href="http://www.cppblog.com/biao/archive/2013/03/14/198416.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>其他编程：版本控制入门简介</title><link>http://www.cppblog.com/biao/archive/2012/04/27/172924.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 27 Apr 2012 07:07:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/04/27/172924.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/172924.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/04/27/172924.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/172924.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/172924.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Verdana; text-align: left; background-color: #e5ecf4; ">版本控制已经出现有些年头了。然而，我还是会被人问起一些，诸如版本控制是什么或者它是如何工作的，这样基础的问题。本文会概括地解释版本控制解决的重要问题，本文使用的场景针对的是源代码版本控制。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Verdana; text-align: left; background-color: #e5ecf4; "><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />目前有很多不同类型的版本控制系统（Version Control System， VCS）。一些VCS，比如<a href="http://subversion.apache.org/" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; ">Subversion</a>和<a href="http://savannah.nongnu.org/projects/cvs" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; ">CVS</a>，以中央仓库（repository）为中心进行架构。此外，还有分布式的VCS（Distributed VCS，DVCS），&nbsp;<a href="http://git-scm.com/" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; ">Git</a>&nbsp;和&nbsp;<a href="http://mercurial.selenic.com/" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; ">Mercurial</a>&nbsp;是两个新近出现的DVCS。然而，在上述两种类型的环境中，通常会有一个&#8220;指定的&#8221;中央仓库。对应地，比如一个Subversion服务器或者一个<a href="https://github.com/" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; ">GitHub</a>仓库。下面会基于这个场景进行图示说明。那么让我们开始吧。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />在开发者拷贝到本机之前，服务器需要创建一个仓库。创建初始仓库会由于产品不同而有所差别。从现在起，你所要知道的就是，在服务器上有一个初始空间。我把这个版本称作版本&#8220;A&#8221;。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><a href="http://img.cnbeta.com/newsimg/120427/08104301990317868.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; "><img title="VCS1" src="http://img.cnbeta.com/newsimg/120427/08104301990317868.png" altwidth="237" style="margin-top: 5px !important; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-style: initial; border-color: initial; border-image: initial; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-width: initial; clear: both; display: block; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-top-left-radius: 6px; border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px; border-top-color: #d4d4d4; border-right-color: #d4d4d4; border-bottom-color: #d4d4d4; border-left-color: #d4d4d4; "  alt="" /></a><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />现在，每个开发者（开发者1和开发者2）都会拷贝版本&#8220;A&#8221;到他们本地电脑。再一次地，从服务器拷贝的过程会由于产品不同采用的技术会有所差别。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><a href="http://img.cnbeta.com/newsimg/120427/0810451132929552.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; "><img title="VCS2" src="http://img.cnbeta.com/newsimg/120427/0810451132929552.png" altwidth="243" style="margin-top: 5px !important; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-style: initial; border-color: initial; border-image: initial; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-width: initial; clear: both; display: block; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-top-left-radius: 6px; border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px; border-top-color: #d4d4d4; border-right-color: #d4d4d4; border-bottom-color: #d4d4d4; border-left-color: #d4d4d4; "  alt="" /></a><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />每个开发者会在他们的本地拷贝上进行开发。他们的本地拷贝基于版本&#8220;A&#8221;。然而，由于他们<em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">应该不会</em>做同样的开发，因而他们的版本会有所差别。因此，会有2个以上的版本会同时被创建，比如版本&#8220;B&#8221;和版本&#8220;C&#8221;。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><a href="http://img.cnbeta.com/newsimg/120427/08104621156274916.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; "><img title="VCS3" src="http://img.cnbeta.com/newsimg/120427/08104621156274916.png" altwidth="317" style="margin-top: 5px !important; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-style: initial; border-color: initial; border-image: initial; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-width: initial; clear: both; display: block; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-top-left-radius: 6px; border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px; border-top-color: #d4d4d4; border-right-color: #d4d4d4; border-bottom-color: #d4d4d4; border-left-color: #d4d4d4; "  alt="" /></a><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />开发者1首先完成了她的工作并提交到服务器。服务器上的当前版本被更新成版本&#8220;B&#8221;。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><a href="http://img.cnbeta.com/newsimg/120427/08104831137474324.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; "><img title="VCS4" src="http://img.cnbeta.com/newsimg/120427/08104831137474324.png" altwidth="317" style="margin-top: 5px !important; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-style: initial; border-color: initial; border-image: initial; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-width: initial; clear: both; display: block; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-top-left-radius: 6px; border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px; border-top-color: #d4d4d4; border-right-color: #d4d4d4; border-bottom-color: #d4d4d4; border-left-color: #d4d4d4; "  alt="" /></a><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />开发者2现在完成了他的工作并试图提交到服务器。然而，这是服务器告知他基于开发的版本已经发生改变。<strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">这也是为什么采取版本控制的首要原因之一。</strong>这个特性是对网络共享代码然后由开发者手动更新的一个跨越式发展，这确保了之前的编辑没有被新的修改覆盖。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><a href="http://img.cnbeta.com/newsimg/120427/08104941810307228.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; "><img title="VCS5" src="http://img.cnbeta.com/newsimg/120427/08104941810307228.png" altwidth="396" style="margin-top: 5px !important; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-style: initial; border-color: initial; border-image: initial; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-width: initial; clear: both; display: block; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-top-left-radius: 6px; border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px; border-top-color: #d4d4d4; border-right-color: #d4d4d4; border-bottom-color: #d4d4d4; border-left-color: #d4d4d4; "  alt="" /></a><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />开发者2必须首先获得所有版本&#8220;B&#8221;的变化，并合并到他的修改中，然后才可以提交到服务器。这个过程听起来有些复杂。然而，大多数现代的版本控制系统十分高级，能够自动在开发者的本地拷贝上完成合并。有几种情况会产生冲突（例如：开发者1和开发者2同时修改了同一个文件的同一行）。这就是一些VCS产品比其他更高级的地方。不论如何完成合并，现在开发者2在他们的本地系统上同时混合了版本B和版本C。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><a href="http://img.cnbeta.com/newsimg/120427/0810515916028618.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; "><img title="VCS6" src="http://img.cnbeta.com/newsimg/120427/0810515916028618.png" altwidth="459" style="margin-top: 5px !important; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-style: initial; border-color: initial; border-image: initial; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-width: initial; clear: both; display: block; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-top-left-radius: 6px; border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px; border-top-color: #d4d4d4; border-right-color: #d4d4d4; border-bottom-color: #d4d4d4; border-left-color: #d4d4d4; "  alt="" /></a><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />现在开发者2可以提交他的版本到服务器。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><a href="http://img.cnbeta.com/newsimg/120427/08105262025047221.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; "><img title="VCS7" src="http://img.cnbeta.com/newsimg/120427/08105262025047221.png" altwidth="410" style="margin-top: 5px !important; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-style: initial; border-color: initial; border-image: initial; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-width: initial; clear: both; display: block; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-top-left-radius: 6px; border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px; border-top-color: #d4d4d4; border-right-color: #d4d4d4; border-bottom-color: #d4d4d4; border-left-color: #d4d4d4; "  alt="" /></a><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />这是一个版本控制的基础。通过注意观察图中服务器的连线可以发现版本控制的原理。服务器记录了所有先前的版本包括发生的变化，什么时候发生以及由谁进行修改。当需要进行代码回溯或者引入其他bug时，这个记录能够解除困境。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />我希望本文能够为版本控制系统提供一个基础的介绍。如果你有任何疑问，请就你问题发表评论。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />英文原文：<a href="http://www.greenmoonsoftware.com/2012/04/04/an-introduction-to-version-control/" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; ">greenmoonsoftware&nbsp;</a>编译：<a href="http://www.jobbole.com/" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; ">伯乐</a>在线 &#8211;&nbsp;<a href="http://blog.jobbole.com/11590/" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #003366; text-decoration: none; ">唐尤华</a></p><img src ="http://www.cppblog.com/biao/aggbug/172924.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-04-27 15:07 <a href="http://www.cppblog.com/biao/archive/2012/04/27/172924.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：Qt正则表达式中匹配中文</title><link>http://www.cppblog.com/biao/archive/2012/03/04/167118.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sun, 04 Mar 2012 08:08:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/03/04/167118.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/167118.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/03/04/167118.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/167118.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/167118.html</trackback:ping><description><![CDATA[<pre style="margin-top: 0px; margin-bottom: 0px; "><!--StartFragment--><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">QRegExp</span><span style=" color:#c0c0c0;"> </span>rx(<span style=" color:#008000;">"[\u4e00-\u9fa5]"</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">QString</span><span style=" color:#c0c0c0;"> </span>str(<span style=" color:#008000;">"我....这是神马"</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">QStringList</span><span style=" color:#c0c0c0;"> </span>list;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">int</span><span style=" color:#c0c0c0;"> </span>pos<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">while</span><span style=" color:#c0c0c0;"> </span>((pos<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>rx.indexIn(str,<span style=" color:#c0c0c0;"> </span>pos))<span style=" color:#c0c0c0;"> </span>!=<span style=" color:#c0c0c0;"> </span>-<span style=" color:#000080;">1</span>)<span style=" color:#c0c0c0;"> </span>{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">        </span>list<span style=" color:#c0c0c0;"> </span>&lt;&lt;<span style=" color:#c0c0c0;"> </span>rx.cap(<span style=" color:#000080;">0</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">        </span>pos<span style=" color:#c0c0c0;"> </span>+=<span style=" color:#c0c0c0;"> </span>rx.matchedLength();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>}</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>qDebug()<span style=" color:#c0c0c0;"> </span>&lt;&lt;<span style=" color:#c0c0c0;"> </span>list;<!--EndFragment--></pre>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/167118.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-03-04 16:08 <a href="http://www.cppblog.com/biao/archive/2012/03/04/167118.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：禁止qDebug的输出</title><link>http://www.cppblog.com/biao/archive/2012/01/16/164244.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 16 Jan 2012 03:50:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/01/16/164244.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/164244.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/01/16/164244.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/164244.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/164244.html</trackback:ping><description><![CDATA[在工程的.pro文件里加上以下编译批令即可：
<div>DEFINES += QT_NO_DEBUG_OUTPUT</div><img src ="http://www.cppblog.com/biao/aggbug/164244.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-01-16 11:50 <a href="http://www.cppblog.com/biao/archive/2012/01/16/164244.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：QGraphicsEffect介绍</title><link>http://www.cppblog.com/biao/archive/2012/01/14/164168.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 14 Jan 2012 06:40:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/01/14/164168.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/164168.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/01/14/164168.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/164168.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/164168.html</trackback:ping><description><![CDATA[<span  style="color: #98834c; font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 25px; ">
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; ">QGraphicsEffect也是Qt-4.6引入的一个新功能。它让给图形元素QGraphicsItem增加更佳视觉效果的编程变得非常简单。</font></p>
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; ">先来看几张效果图。</font></p>
<table width="540" style="line-height: 25px; height: 488px; ">
    <tbody style="line-height: 25px; ">
        <tr style="line-height: 25px; ">
            <td colspan="2" style="line-height: 25px; text-align: center; "><font size="2" style="line-height: 23px; "><img alt="" src="http://docs.google.com/File?id=dhhvrcmh_204c8x3vtgm_b" style="line-height: 23px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; max-width: 100%; " /></font></td>
        </tr>
        <tr style="line-height: 25px; ">
            <td style="line-height: 25px; text-align: center; "><font size="2" style="line-height: 23px; "><img alt="" src="http://docs.google.com/File?id=dhhvrcmh_205hfv468g9_b" width="250" style="line-height: 23px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; max-width: 100%; " /></font></td>
            <td style="line-height: 25px; text-align: center; "><font size="2" style="line-height: 23px; "><img alt="" src="http://docs.google.com/File?id=dhhvrcmh_207gs43jgtj_b" width="250" style="line-height: 23px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; max-width: 100%; " /></font></td>
        </tr>
        <tr style="line-height: 25px; ">
            <td style="line-height: 25px; text-align: center; "><font size="2" style="line-height: 23px; "><img alt="" src="http://docs.google.com/File?id=dhhvrcmh_208z587dbc2_b" width="250" style="line-height: 23px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; max-width: 100%; " /></font></td>
            <td style="line-height: 25px; text-align: center; "><font size="2" style="line-height: 23px; "><img alt="" src="http://docs.google.com/File?id=dhhvrcmh_209gm53ngfq_b" width="250" style="line-height: 23px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; max-width: 100%; " /></font></td>
        </tr>
    </tbody>
</table>
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; ">上图中最上面的那个图片是没有使用QGraphicsEffect处理的原图，下面的四个图片分别代表了模糊，变色，透明和阴影效果。对应使用了QGraphicsEffect的4个子类QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsDropShadowEffect, 和 QGraphicsOpacityEffect.下面分别介绍它们。<span id="more-1407" style="line-height: 23px; "></span></font></p>
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; "><strong style="line-height: 23px; ">QGraphicsBlurEffect</strong><br style="line-height: 23px; " />
该类用应产生模糊效果,主要函数setBlurRadius(qreal blurRadius),用于控制图形元素的模糊度，数值越大越模糊。使用该类例子如下</font></p>
<blockquote style="line-height: 25px; font-size: 1em; margin-top: auto; margin-right: 0px; margin-bottom: auto; margin-left: 35px; ">
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; ">QGraphicsBlurEffect *e0 = new QGraphicsBlurEffect(this);<br style="line-height: 23px; " />
e0-&gt;setBlurRadius(0.2);<br style="line-height: 23px; " />
item[0]-&gt;setGraphicsEffect(e1);//item[0] 为QGraphicsItem指针</font></p>
</blockquote>
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; "><strong style="line-height: 23px; ">QGraphicsColorizeEffect</strong><br style="line-height: 23px; " />
该类提供了使用另外一种颜色对当前图形的一种着色功能。主要函数是setColor(QColor)和setStrength (qreal strength)，指定了着色和着色强度。使用该类例子如下</font></p>
<blockquote style="line-height: 25px; font-size: 1em; margin-top: auto; margin-right: 0px; margin-bottom: auto; margin-left: 35px; ">
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; ">QGraphicsColorizeEffect *e1 = new QGraphicsColorizeEffect(this);<br style="line-height: 23px; " />
e1-&gt;setColor(QColor(0,0,192));<br style="line-height: 23px; " />
item[1]-&gt;setGraphicsEffect(e1);</font></p>
</blockquote>
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; "><strong style="line-height: 23px; ">QGraphicsDropShadowEffect</strong><br style="line-height: 23px; " />
该类提供了图形元素的阴影效果，用于增加立体感。主要设置函数有3个，setColor()用于设定阴影的颜色,setBlurRadius()用于设定阴影的模糊度，setOffset (qreal dx,qreal dy)用于设定在哪个方向产生阴影效果，如果dx为负数，则阴影在图形元素的左边。使用该类例子如下</font></p>
<blockquote style="line-height: 25px; font-size: 1em; margin-top: auto; margin-right: 0px; margin-bottom: auto; margin-left: 35px; ">
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; ">QGraphicsDropShadowEffect *e2 = new QGraphicsDropShadowEffect(this);<br style="line-height: 23px; " />
e2-&gt;setOffset(8,8);<br style="line-height: 23px; " />
item[2]-&gt;setGraphicsEffect(e2);</font></p>
</blockquote>
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; "><strong style="line-height: 23px; ">QGraphicsOpacityEffect</strong><br style="line-height: 23px; " />
该类用于图形元素的透明效果，主要函数是setOpacity(qreal opacity)，用于设置透明度，参数值在0和1.0之间。也可以设置部分透明效果，需要调用的函数是setOpacityMask (QBrush mask)。使用该类例子如下</font></p>
<blockquote style="line-height: 25px; font-size: 1em; margin-top: auto; margin-right: 0px; margin-bottom: auto; margin-left: 35px; ">
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; ">QGraphicsOpacityEffect *e3 = new QGraphicsOpacityEffect(this);<br style="line-height: 23px; " />
e3-&gt;setOpacity(0.7);<br style="line-height: 23px; " />
item[3]-&gt;setGraphicsEffect(e3);</font></p>
</blockquote>
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; ">下面我是写的</font><a rel="nofollow" href="http://www.cuteqt.com/blog/wp-content/uploads/2010/02/t_effect.zip" style="line-height: 25px; text-decoration: none; color: #ad8674; "><strong style="line-height: 25px; "><font size="2" color="#008000" style="line-height: 23px; ">例子代码</font></strong></a><font size="2" style="line-height: 23px; ">和截图。</font></p>
<div id="o6b-" style="line-height: 25px; text-align: left; "><font size="2" style="line-height: 23px; "><img alt="" src="http://docs.google.com/File?id=dhhvrcmh_210dxw8hkfm_b" style="line-height: 23px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; max-width: 100%; width: 546px; height: 565px; " /></font></div>
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; ">最后值得一提的是，这些效果是可以互相组合的。如果能把这些效果和Qt的动画Animation API结合起来，写出的程序就更漂亮了。<br style="line-height: 23px; " />
$QTSRC/examples/effect目录下面有些例子可以参考。</font></p>
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; "><br />
</font></p>
<p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font size="2" style="line-height: 23px; ">From:&nbsp;http://cowboy.1988.blog.163.com/blog/static/75105798201151311244982/</font></p>
</span>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/164168.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-01-14 14:40 <a href="http://www.cppblog.com/biao/archive/2012/01/14/164168.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：使用自定义的字体</title><link>http://www.cppblog.com/biao/archive/2012/01/01/163345.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sun, 01 Jan 2012 06:41:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/01/01/163345.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/163345.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/01/01/163345.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/163345.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/163345.html</trackback:ping><description><![CDATA[1. 下载字体文件
<div>2. 加载字体文件</div>
<div>3. 使用字体</div>
<div><br />
</div>
<div>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><!--StartFragment--><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">QFontDatabase</span><span style=" color:#000000;">::</span>addApplicationFont<span style=" color:#000000;">(</span><span style=" color:#008000;">"XENOTRON.TTF"</span><span style=" color:#000000;">);</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800000;">ui</span><span style=" color:#000000;">-&gt;</span><span style=" color:#800000;">toolButton_2</span><span style=" color:#000000;">-&gt;</span>setFont<span style=" color:#000000;">(</span><span style=" color:#800080;">QFont</span><span style=" color:#000000;">(</span><span style=" color:#008000;">"XENOTRON"</span><span style=" color:#000000;">,</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">34</span><span style=" color:#000000;">));</span><!--EndFragment--></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000000;"><br />
</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000000;"><img src="http://www.cppblog.com/images/cppblog_com/biao/customize-font.png" width="270" height="213" alt="" /></span></pre>
</div><img src ="http://www.cppblog.com/biao/aggbug/163345.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-01-01 14:41 <a href="http://www.cppblog.com/biao/archive/2012/01/01/163345.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：Qt计算MD5</title><link>http://www.cppblog.com/biao/archive/2011/12/22/162572.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 22 Dec 2011 01:45:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2011/12/22/162572.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/162572.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2011/12/22/162572.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/162572.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/162572.html</trackback:ping><description><![CDATA[<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000080;">#include</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">&lt;QCryptographicHash&gt;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000080;">#include</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">&lt;QDebug&gt;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#008000;"><br />
</span></pre>
<pre style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#808000;">int</span><span style=" color:#c0c0c0;"> </span>main<span style=" color:#000000;">(</span><span style=" color:#808000;">int</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">argc</span><span style=" color:#000000;">,</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">char</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">*</span><span style=" color:#000000;">argv</span><span style=" color:#000000;">[])</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">{</span></pre>
<pre style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span>qDebug<span style=" color:#000000;">()</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">&lt;&lt;</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">QCryptographicHash</span><span style=" color:#000000;">::</span>hash<span style=" color:#000000;">(</span><span style=" color:#008000;">"Biao"</span><span style=" color:#000000;">,</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">QCryptographicHash</span><span style=" color:#000000;">::</span><span style=" color:#800080;">Md5</span><span style=" color:#000000;">).</span>toHex<span style=" color:#000000;">().</span>constData<span style=" color:#000000;">();</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000000;">
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><!--StartFragment--><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">return</span><span style=" color:#c0c0c0;"> 0</span><span style=" color:#000000;">;</span><!--EndFragment--></pre>
</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000000;">}</span><!--EndFragment--></pre><img src ="http://www.cppblog.com/biao/aggbug/162572.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2011-12-22 09:45 <a href="http://www.cppblog.com/biao/archive/2011/12/22/162572.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：去掉QtCreator搜索重复的结果</title><link>http://www.cppblog.com/biao/archive/2011/12/19/162418.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 19 Dec 2011 12:27:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2011/12/19/162418.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/162418.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2011/12/19/162418.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/162418.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/162418.html</trackback:ping><description><![CDATA[例如搜索QString时，会弹出一个窗口让选择使用哪个文档里的QString，很烦人，在设置里删除重复的文档即可，如图@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div><img src="http://www.cppblog.com/images/cppblog_com/biao/qt-help.png" width="796" height="342" alt="" /><br />
</div><img src ="http://www.cppblog.com/biao/aggbug/162418.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2011-12-19 20:27 <a href="http://www.cppblog.com/biao/archive/2011/12/19/162418.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：QDirIterator遍历目录</title><link>http://www.cppblog.com/biao/archive/2011/12/02/161309.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 01 Dec 2011 16:19:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2011/12/02/161309.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/161309.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2011/12/02/161309.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/161309.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/161309.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 遍历一个目录下的所有文件，使用QDirIterator很方便，不需要自己去实现递归：void Widget::browse() {    QString path = QFileDialog::getExistingDirectory(this, tr(""), "/Users/Biao/Desktop");    QDirIterator iter(path, QDirItera...&nbsp;&nbsp;<a href='http://www.cppblog.com/biao/archive/2011/12/02/161309.html'>阅读全文</a><img src ="http://www.cppblog.com/biao/aggbug/161309.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2011-12-02 00:19 <a href="http://www.cppblog.com/biao/archive/2011/12/02/161309.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：Qt Creator一运行工程，总是编译所有的文件</title><link>http://www.cppblog.com/biao/archive/2011/11/17/160303.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 16 Nov 2011 17:35:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2011/11/17/160303.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/160303.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2011/11/17/160303.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/160303.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/160303.html</trackback:ping><description><![CDATA[对Qt Creator和QtSDK的设置一点都没有动过，可是在Qt Creator中一运行工程，即使没有修改过任何工程中的文件，但是总会先要编译所有的文件，然后才能运行。新创建的工程却不会这样，见鬼了？
<div><br />
</div>
<div>工程每编译一次都要几分钟，难不成每做一点修改都要等几分钟才行？</div>
<div><br />
<div>先前这个工程还是正常的，为何现在却变成这样了？难不成见鬼了？</div>
<div>不是见鬼，因果循环，只是我们没有找到原因罢了。</div>
<div><br />
</div>
<div>Qt Creator always rebuild all the files in the project，在Google上搜索这句话，得到唯一相关的答案是 " I have forgot adjust the date and time settings."，没有找到其他有用的信息了，但重要的一点是无意中看到了时间设置这个关键，找了Qt Creator相关设置，没有啊。</div>
</div>
<div><br />
</div>
<div>后来观察文件的属性，发现还真是时间的问题，例如现在是2011－11－16，而那些文件的修改时间是2011－12－24，原来由于测试的需要，我把系统的时间调到了2011－12－24，修改程序，然后再测试，这样很多文件的修改时间都是2011－12－24了，再调回到2011－11－16，在Qt Creator中运行工程时，Qt Creator先查看了文件的修改时间，认为这些文件都是修改过的，所以都要编译一次，然后才运行。</div>
<div><br />
</div>
<div>为了验证这个想法，把系统时间再调到2011－12－24以后，再运行工程，一切正常了，没有修改过的文件就不会再编译了，哎，业务不熟，害死人。</div><img src ="http://www.cppblog.com/biao/aggbug/160303.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2011-11-17 01:35 <a href="http://www.cppblog.com/biao/archive/2011/11/17/160303.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：极致的典雅，Style sheet</title><link>http://www.cppblog.com/biao/archive/2011/11/10/159897.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 09 Nov 2011 18:14:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2011/11/10/159897.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/159897.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2011/11/10/159897.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/159897.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/159897.html</trackback:ping><description><![CDATA[<img src="http://www.cppblog.com/images/cppblog_com/biao/card-decorate.png" width="1088" height="706" alt="" />
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/159897.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2011-11-10 02:14 <a href="http://www.cppblog.com/biao/archive/2011/11/10/159897.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：使用系统默认的程序打开对应的文件</title><link>http://www.cppblog.com/biao/archive/2011/11/04/159617.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 04 Nov 2011 06:29:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2011/11/04/159617.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/159617.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2011/11/04/159617.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/159617.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/159617.html</trackback:ping><description><![CDATA[<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<span  style="border-collapse: collapse; color: #333333; font-family: Arial; ">QDesktopServices提供了一些系统相关的功能。</span>
<div><span  style="font-family: Arial; line-height: normal; font-size: medium; "><span style="border-collapse: separate; color: #000000; font-family: 'Hiragino Sans GB'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; "><span style="border-collapse: collapse; color: #333333; font-family: Arial; font-size: 14px; line-height: 21px; "><br />
</span></span></span></div>
<div><span  style="font-family: Arial; line-height: normal; font-size: medium; "><span style="border-collapse: separate; color: #000000; font-family: 'Hiragino Sans GB'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; "><span style="border-collapse: collapse; color: #333333; font-family: Arial; font-size: 14px; line-height: 21px; ">打开桌面上的1.mp4视频文件<br style="outline-style: none; outline-width: initial; outline-color: initial; " />
QDesktopServices::openUrl(QUrl("file:////Users/Biao/Desktop/1.mp4"));<br style="outline-style: none; outline-width: initial; outline-color: initial; " />
<br style="outline-style: none; outline-width: initial; outline-color: initial; " />
</span></span></span>
<div style="font-family: Arial; line-height: normal; font-size: medium; "><span  style="border-collapse: collapse; color: #333333; font-size: 14px; line-height: 21px; ">The openUrl() function is used to open files located at arbitrary URLs in external applications. For URLs that correspond to resources on the local filing system (where the URL scheme is "file"), a suitable application will be used to open the file; otherwise, a web browser will be used to fetch and display the file.</span></div>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
</div><img src ="http://www.cppblog.com/biao/aggbug/159617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2011-11-04 14:29 <a href="http://www.cppblog.com/biao/archive/2011/11/04/159617.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：分页组件</title><link>http://www.cppblog.com/biao/archive/2011/10/30/159350.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sun, 30 Oct 2011 04:31:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2011/10/30/159350.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/159350.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2011/10/30/159350.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/159350.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/159350.html</trackback:ping><description><![CDATA[@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<img src="http://www.cppblog.com/images/cppblog_com/biao/page.png" width="595" height="220" alt="" />&nbsp;
<div><br />
</div>
<div>使用非常简单:</div>
<div>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><!--StartFragment--><span style=" color:#c0c0c0;">    </span><span style=" color:#008000;">//</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">把分页组件加入到当前窗口</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800000;">pageWidget</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">new</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">PageWidget</span><span style=" color:#000000;">();</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><span style=" color:#c0c0c0;">    </span>layout<span style=" color:#000000;">()-&gt;</span>addWidget<span style=" color:#000000;">(</span><span style=" color:#800000;">pageWidget</span><span style=" color:#000000;">);</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><span style=" color:#000000;">
</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><span style=" color:#000000;">当总页数改变时(如查询数据库操作得到总页数)，只需要调用pageWidget的两个函数</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; ">
<pre style="color: #000000; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><!--StartFragment--><span style=" color:#808000;">void</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">Widget</span><span style=" color:#000000;">::</span>changeMaxPage<span style=" color:#000000;">()</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">{</span></pre>
<pre style="color: #000000; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800000;">pageWidget</span><span style=" color:#000000;">-&gt;</span>setMaxPage<span style=" color:#000000;">(</span><span style=" color:#800000;">ui</span><span style=" color:#000000;">-&gt;</span><span style=" color:#800000;">lineEdit</span><span style=" color:#000000;">-&gt;</span>text<span style=" color:#000000;">().</span>toInt<span style=" color:#000000;">());</span></pre>
<pre style="color: #000000; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800000;">pageWidget</span><span style=" color:#000000;">-&gt;</span>setCurrentPage<span style=" color:#000000;">(</span><span style=" color:#000080;">1</span><span style=" color:#000000;">);</span></pre>
<pre style="color: #000000; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><span style=" color:#000000;">}</span><!--EndFragment--></pre>
<pre style="color: #000000; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><span style=" color:#000000;"><br />
</span></pre>
<pre style="color: #000000; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><span style=" color:#000000;">当pageWidget上的页码被点击后，会发射</span><span style=" color:#808000;">void</span><span style=" color:#c0c0c0;"> </span>currentPageChanged<span style=" color:#000000;">(</span><span style=" color:#808000;">int</span><span style=" color:#c0c0c0;"> </span>page<span style=" color:#000000;">)</span>信号，然后主窗口里再作出相应反应，如查询分页查询数据库</pre>
<pre style="color: #000000; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><br />
</pre>
<pre style="color: #000000; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; ">工程文件下载：<a href="/Files/biao/MultiPageDemo.7z">/Files/biao/MultiPageDemo.7z</a></pre>
</pre>
</div><img src ="http://www.cppblog.com/biao/aggbug/159350.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2011-10-30 12:31 <a href="http://www.cppblog.com/biao/archive/2011/10/30/159350.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：Windows下编译MySql驱动</title><link>http://www.cppblog.com/biao/archive/2011/10/29/159296.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 28 Oct 2011 16:58:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2011/10/29/159296.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/159296.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2011/10/29/159296.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/159296.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/159296.html</trackback:ping><description><![CDATA[<div><br />
</div>
Mac OS X编译安装MySql是件非常轻松的活，在Windows里却花了很久。
<div><br />
<div>系统: Windows</div>
<div>Qt: 直接使用Qt SDK安装的，所以得手动把bin目录设置到环境路径下</div>
<div>Mysql: 下载最新社区版</div>
<div>黄色背景部分为关键部分</div>
<div><br />
</div>
<div><span style="color: red; background-color: yellow; font-size: 14pt; ">总的步骤：</span></div>
<div>1. 生成mingw使用的mysql的libmysql.a文件</div>
<div>2. qmake生成mysql.pro文件</div>
<div>3. 把includepath和libs的内容加入到mysql.pro文件</div>
<div>4. make, make release 生成mysql的驱动文件</div>
<div>5. 复制生成的驱动文件到qt的数据库驱动文件夹</div>
<div>6. 复制mysql的lib/libmysql.dll到qt的bin文件夹</div>
<div><br />
</div>
<div>MySQL: <span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; ">安装时不要用经典安装，选择完全安装或者自定义把头文件和库勾选上，这样安装后会有for c/c++的头文件和库目录，MySql我就安装在C盘根目录下了</span></div>
<div>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a target="_blank" href="http://img1.51cto.com/attachment/201109/132651936.jpg" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #015f91; text-decoration: none; "><img border="0" alt="" src="http://img1.51cto.com/attachment/201109/132651936.jpg" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; vertical-align: top; border-style: initial; border-color: initial; border-style: initial; border-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial; border-width: initial; border-color: initial; " /></a></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">因为这里我们使用MinGW来编译驱动，mysql提供的这个libmysql.lib我们还不能直接用(如果用微软的编译器就不用这样了），我们需要用个工具转成*.a来用。</p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">工具下载：<span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; ">&nbsp;</span><span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; "><a href="http://www.qtcn.org/download/mingw-utils-0.3.tar.gz" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #336699; text-decoration: none; ">http://www.qtcn.org/download/mingw-utils-0.3.tar.gz</a></span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">解压我们只用<span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; ">remip.exe这个东西，把他放在你的mingw/bin和那些make.exe放一起就行。</span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; ">cd C:/mysql/lib</span></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="font-family: 'Courier New', monospace; font-size: 12px; line-height: 15px; white-space: pre; "><span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial; color: black; background-color: yellow; ">reimp&nbsp;-d&nbsp;libmysql.lib</span><span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;(生成&nbsp;libmysql.def文件)</span></span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; "><span style="color: #5c5c5c; font-family: 'Courier New', monospace; font-size: 12px; line-height: 15px; white-space: pre; "><span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial; color: black; background-color: yellow; ">dlltool&nbsp;-k&nbsp;-d&nbsp;libmysql.def&nbsp;-l&nbsp;libmysql.a</span><span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;(生成&nbsp;libmysql.a文件)</span></span></span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a target="_blank" href="http://img1.51cto.com/attachment/201109/134538140.jpg" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #015f91; text-decoration: none; "><img border="0" alt="" src="http://img1.51cto.com/attachment/201109/134538140.jpg" width="650" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; vertical-align: top; border-style: initial; border-color: initial; border-style: initial; border-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial; border-width: initial; border-color: initial; " /></a></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">over了，出来这2个东西了。</p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a target="_blank" href="http://img1.51cto.com/attachment/201109/134621510.jpg" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #015f91; text-decoration: none; "><img border="0" alt="" src="http://img1.51cto.com/attachment/201109/134621510.jpg" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; vertical-align: top; border-style: initial; border-color: initial; border-style: initial; border-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial; border-width: initial; border-color: initial; " /></a></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">好了需要的libmysql.a准备好了</p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">下面开始编译之旅：</p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">来到qt mysql驱动的源程序目录，有个cpp文件和一个qt项目文件。</p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a target="_blank" href="http://img1.51cto.com/attachment/201109/134949295.jpg" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #015f91; text-decoration: none; "><img border="0" alt="" src="http://img1.51cto.com/attachment/201109/134949295.jpg" width="650" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; vertical-align: top; border-style: initial; border-color: initial; border-style: initial; border-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial; border-width: initial; border-color: initial; " /></a></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; ">cd %QTDIR%/src/plugins/sqldrivers/mysql （</span>当前目录转到源程序目录）</p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="background-color: yellow; ">qmake -o Makefile "INCLUDEPATH+=C:/mysql/include" "LIBS+=C:/mysql/lib/libmysql.a" mysql.pro</span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">（<span style="color: red; ">如果你的mysql安装在其他地方，如果路径上有空格之类的，直接复制include和lib目录到C盘根目录下的mysql目录好了，方便一会写路径。）</span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">接下来的步骤很关键，开始的时候没有使用下面的方式，弄了很久都不行。</p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="background-color: yellow; ">在刚刚生成的</span><span style="color: #333333; font-family: Arial; line-height: normal; background-color: yellow; ">mysql.pro中加入以下：</span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="color: #333333; font-family: Arial; line-height: normal; ">INCLUDEPATH+="C:/mysql/include"<br style="line-height: normal; " />
LIBS+="C:/mysql/lib/libmysql.lib"<br style="line-height: normal; " />
HEADERS =../../../sql/drivers/mysql/qsql_mysql.h<br style="line-height: normal; " />
SOURCES = main.cpp\<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../../../sql/drivers/mysql/qsql_mysql.cpp</span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="color: #333333; font-family: Arial; line-height: normal; "><br />
</span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="color: #333333; font-family: Arial; line-height: normal; ">然后</span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="color: #333333; font-family: Arial; line-height: normal; background-color: yellow; ">make</span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="color: #333333; font-family: Arial; line-height: normal; background-color: yellow; ">make release</span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="color: #333333; font-family: Arial; line-height: normal; ">至此在debug和release目录里生成了下面的这四个文件</span></p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="color: #333333; font-family: Arial; line-height: normal; "><span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; ">
</span></span></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a target="_blank" href="http://img1.51cto.com/attachment/201109/135542193.jpg" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #015f91; text-decoration: none; "><img border="0" alt="" src="http://img1.51cto.com/attachment/201109/135542193.jpg" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; vertical-align: top; border-style: initial; border-color: initial; border-style: initial; border-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial; border-width: initial; border-color: initial; " /></a></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a target="_blank" href="http://img1.51cto.com/attachment/201109/135601879.jpg" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #015f91; text-decoration: none; "><img border="0" alt="" src="http://img1.51cto.com/attachment/201109/135601879.jpg" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; vertical-align: top; border-style: initial; border-color: initial; border-style: initial; border-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial; border-width: initial; border-color: initial; " /></a></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br />
</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="background-color: yellow; ">复制上面的这4个文件到qt的plugins/sqldrivers目录：例如我的：C:/QtSDK/Desktop/Qt/4.7.4/mingw/plugins/sqldrivers</span></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="background-color: yellow; ">同时也要把mysql/lib/libmysql.dll这个文件复制到qt的bin目录：例如我的：C:/QtSDK/Desktop/Qt/4.7.4/mingw/bin</span></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br />
</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">From:&nbsp;http://xcf007.blog.51cto.com/471707/672917,&nbsp;http://hi.baidu.com/bodogbo/blog/item/e1ac85d156a88c1b3bf3cf76.html</p>
<p>&nbsp;</p>
<p style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 15px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="color: #333333; font-family: Arial; line-height: normal; "><br />
</span></p>
</div>
<div><span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; "><br />
</span></div>
</div><img src ="http://www.cppblog.com/biao/aggbug/159296.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2011-10-29 00:58 <a href="http://www.cppblog.com/biao/archive/2011/10/29/159296.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：免费的MySQL管理客戶端</title><link>http://www.cppblog.com/biao/archive/2011/10/28/159288.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 28 Oct 2011 14:47:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2011/10/28/159288.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/159288.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2011/10/28/159288.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/159288.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/159288.html</trackback:ping><description><![CDATA[<div style="text-align: left;"><span  style="border-collapse: collapse; font-family: 'Lucida Grande', Calibri, 'Trebuchet MS', Helvetica, Arial, 'Hiragino Sans GB', 'WenQuanYi Micro Hei', STHeiti, 'Microsoft Jhenghei', sans-serif; font-size: 13px; ">官方站點：<a href="http://www.sequelpro.com/" target="_blank" style="word-wrap: break-word; text-decoration: none; color: #355491; line-height: normal; ">http://www.sequelpro.com</a></span></div>
<span  style="border-collapse: collapse; font-family: 'Lucida Grande', Calibri, 'Trebuchet MS', Helvetica, Arial, 'Hiragino Sans GB', 'WenQuanYi Micro Hei', STHeiti, 'Microsoft Jhenghei', sans-serif; font-size: 13px; "><br style="word-wrap: break-word; line-height: normal; " />
Sequel Pro 的原名是 CocoaMySQL，是一个与 phpMyAdmin 類似的 MySQL 管理<span href="tag.php?name=%B9%A4%BE%DF" class="t_tag" style="word-wrap: break-word; line-height: normal; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #aaaaaa; cursor: pointer; white-space: nowrap; ">工具</span>。它是由 Cocoa 和面对对象的C（<span href="tag.php?name=Mac" class="t_tag" style="word-wrap: break-word; line-height: normal; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #aaaaaa; cursor: pointer; white-space: nowrap; ">Mac</span>&nbsp;OS X）编写的。Sequel Pro 允许你编辑数据库，表格（字段和索引）和列，执行个性化查找和导入导出数据。<br style="word-wrap: break-word; line-height: normal; " />
<br style="word-wrap: break-word; line-height: normal; " />
<img src="http://mac.pcbeta.com/attachments/month_0909/09090321199c13122b7538aeef.jpg" file="attachments/month_0909/09090321199c13122b7538aeef.jpg" width="600" id="aimg_2613" alt="螢幕快照 2009-09-04 上午9.06.48.jpg" class="" style="word-wrap: break-word; line-height: normal; border-top-left-radius: 3px 3px; border-top-right-radius: 3px 3px; border-bottom-right-radius: 3px 3px; border-bottom-left-radius: 3px 3px; " />&nbsp;<br style="word-wrap: break-word; line-height: normal; " />
<br style="word-wrap: break-word; line-height: normal; " />
<img src="http://mac.pcbeta.com/attachments/month_0909/09090321192d3d293868347e4a.jpg" file="attachments/month_0909/09090321192d3d293868347e4a.jpg" width="600" id="aimg_2614" alt="螢幕快照 2009-09-04 上午9.05.39.jpg" class="" style="word-wrap: break-word; line-height: normal; border-top-left-radius: 3px 3px; border-top-right-radius: 3px 3px; border-bottom-right-radius: 3px 3px; border-bottom-left-radius: 3px 3px; " />&nbsp;<br style="word-wrap: break-word; line-height: normal; " />
<br style="word-wrap: break-word; line-height: normal; " />
<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">注：目前國內大部分虛擬主機服務提供商沒有開啓MySQL的遠端連線<span href="tag.php?name=%B9%A6%C4%DC" class="t_tag" style="word-wrap: break-word; line-height: normal; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #aaaaaa; cursor: pointer; white-space: nowrap; ">功能</span>，如果您使用的是VPS或獨立伺服器，需要修改 my.cnf (*Unix) my.ini (<span href="tag.php?name=Windows" class="t_tag" style="word-wrap: break-word; line-height: normal; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #aaaaaa; cursor: pointer; white-space: nowrap; ">Windows</span>) 內參數，才能在本地使用此軟體連線管理資料庫</strong><br style="word-wrap: break-word; line-height: normal; " />
<br style="word-wrap: break-word; line-height: normal; " />
<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">下載地址：<a href="http://sequel-pro.googlecode.com/files/sequel-pro-0.9.6.dmg" target="_blank" style="word-wrap: break-word; text-decoration: none; color: #355491; line-height: normal; ">http://sequel-pro.googlecode.com/files/sequel-pro-0.9.6.dmg</a></strong></span>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div><span  style="border-collapse: collapse; font-family: 'Lucida Grande', Calibri, 'Trebuchet MS', Helvetica, Arial, 'Hiragino Sans GB', 'WenQuanYi Micro Hei', STHeiti, 'Microsoft Jhenghei', sans-serif; font-size: 13px; "><br />
</span></div>
<div><span  style="border-collapse: collapse; font-family: 'Lucida Grande', Calibri, 'Trebuchet MS', Helvetica, Arial, 'Hiragino Sans GB', 'WenQuanYi Micro Hei', STHeiti, 'Microsoft Jhenghei', sans-serif; font-size: 13px; ">From：http://mac.pcbeta.com/thread-2562-1-1.html</span></div><img src ="http://www.cppblog.com/biao/aggbug/159288.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2011-10-28 22:47 <a href="http://www.cppblog.com/biao/archive/2011/10/28/159288.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：Mac中使用压缩包的mysql(非安装版)</title><link>http://www.cppblog.com/biao/archive/2011/10/28/159284.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Fri, 28 Oct 2011 13:21:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2011/10/28/159284.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/159284.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2011/10/28/159284.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/159284.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/159284.html</trackback:ping><description><![CDATA[@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
1. 下载mysql的 tar包 http://www.mysql.com/downloads/mysql/5.5.html@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&amp;file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div>2. 解压，然后复制到/usr/local 目录下</div>
<div>3. 修改 /usr/local/mysql的所有者为mysql： chown -R mysql:mysql mysql (反正是这一步给做了，不知道是不是必须的)</div>
<div>4. 安装mysql ? : <span style="color: red; ">sudo /usr/local/mysql/scripts/mysql_install_db&nbsp;</span></div>
<div>5. 至此，可以运行mysql服务器端了:&nbsp;sudo /usr/local/mysql/bin/mysqld_safe &amp; &nbsp; (&amp;在Unix系统里并不会在后台运行，尤其是使用像tomcat时非常有用，可以看得到输出的信息)</div>
<div><br />
</div>
<div>6. 运行mysql客户端: <span style="color: red; ">/usr/local/mysql/bin/mysql -u root -p</span></div><img src ="http://www.cppblog.com/biao/aggbug/159284.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2011-10-28 21:21 <a href="http://www.cppblog.com/biao/archive/2011/10/28/159284.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>