??xml version="1.0" encoding="utf-8" standalone="yes"?>久久综合色之久久综合,国产精品久久久久天天影视,亚洲AV无码成人网站久久精品大http://www.shnenglu.com/erran/category/14071.htmlzh-cnSat, 19 Jun 2010 02:56:26 GMTSat, 19 Jun 2010 02:56:26 GMT60转:QT的信号与槽机制介l?/title><link>http://www.shnenglu.com/erran/archive/2010/06/18/118185.html</link><dc:creator>erran</dc:creator><author>erran</author><pubDate>Fri, 18 Jun 2010 10:11:00 GMT</pubDate><guid>http://www.shnenglu.com/erran/archive/2010/06/18/118185.html</guid><wfw:comment>http://www.shnenglu.com/erran/comments/118185.html</wfw:comment><comments>http://www.shnenglu.com/erran/archive/2010/06/18/118185.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/erran/comments/commentRss/118185.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/erran/services/trackbacks/118185.html</trackback:ping><description><![CDATA[ <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="31"> <tbody sizcache="1" sizset="31"> <tr valign="top"> <td width="10" height="18"> </td> <td width="100%"> <img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="1" /> <br /> <a class="bctl" > <font color="#999999" size="2">developerWorks 中国</font> </a> <span id="pxzfbfp" class="bct"> <font color="#cccccc" size="2">  >  </font> </span> <a class="bctl" > <font color="#999999" size="2">Linux</font> </a> <font size="2"> <font color="#cccccc"> <span id="tpxjdnp" class="bct">  ></span> <img height="1" alt="" src="http://www.ibm.com/i/c.gif" width="1" /> <br /> </font> </font> <h1>QT的信号与槽机制介l?/h1> <img class="display-img" height="6" alt="" src="http://www.ibm.com/i/c.gif" width="1" /> </td> <td class="no-print" width="192"> <img height="18" alt="developerWorks" src="http://www.ibm.com/developerworks/i/dw.gif" width="192" /> </td> </tr> </tbody> </table> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="32"> <tbody sizcache="2" sizset="33"> <tr valign="top" sizcache="2" sizset="33"> <td width="10"> <img height="1" alt="" src="http://www.ibm.com/i/c.gif" width="10" /> </td> <td width="100%" sizcache="2" sizset="33"> <table class="no-print" cellspacing="0" cellpadding="0" width="160" align="right" border="0" sizcache="2" sizset="33"> <tbody sizcache="2" sizset="34"> <tr sizcache="2" sizset="34"> <td width="10"> <img height="1" alt="" src="http://www.ibm.com/i/c.gif" width="10" /> </td> <td sizcache="2" sizset="34"> <table cellspacing="0" cellpadding="0" width="150" border="0" sizcache="2" sizset="34"> <tbody sizcache="1" sizset="34"> <tr> <td class="v14-header-1-small">文选项</td> </tr> </tbody> </table> <table class="v14-gray-table-border" cellspacing="0" cellpadding="0" border="0" sizcache="2" sizset="35"> <tbody sizcache="2" sizset="36"> <tr sizcache="2" sizset="36"> <td class="no-padding" width="150" sizcache="2" sizset="36"> <table cellspacing="0" cellpadding="0" width="143" border="0" sizcache="2" sizset="36"> <script language="JavaScript" type="text/javascript"> <!-- document.write('<tr valign="top"><td width="8"><img src="http://www.ibm.com/i/c.gif" width="8" height="1" alt=""/></td><td width="16"><img alt="打印机的版面设|成横向打印模式" height="16" src="http://www.ibm.com/i/v14/icons/printer.gif" width="16" vspace="3" /></td><td width="122"><p><b><a class="smallplainlink" href="javascript:print()">打印本页</a></b></p></td></tr>'); //--> </script> <tbody sizcache="1" sizset="36"> <tr valign="top"> <td width="8"> <img height="1" alt="" src="http://www.ibm.com/i/c.gif" width="8" /> </td> <td width="16"> <img height="16" alt="打印机的版面设|成横向打印模式" src="http://www.ibm.com/i/v14/icons/printer.gif" width="16" vspace="3" /> </td> <td width="122"> <p> <b> <a class="smallplainlink" href="javascript:print()">打印本页</a> </b> </p> </td> </tr> <noscript> </noscript> <form name="email" action="https://www.ibm.com/developerworks/secure/email-it.jsp" sizcache="1" sizset="37"> <input type="hidden" value="信号与槽作ؓQT的核心机制在QT~程中有着q泛的应用,本文介绍了信号与槽的一些基本概c元对象工具以及在实际用过E中应注意的一些问题? name="body" /> <input type="hidden" value="QT的信号与槽机制介l? name="subject" /> <input type="hidden" value="cn" name="lang" /> <script language="JavaScript" type="text/javascript"> <!-- document.write('<tr valign="top"><td width="8"><img src="http://www.ibm.com/i/c.gif" width="8" height="1" alt=""/></td><td width="16"><img src="http://www.ibm.com/i/v14/icons/em.gif" height="16" width="16" vspace="3" alt="此作为电子邮件发? /></td><td width="122"><p><a class="smallplainlink" href="javascript:document.email.submit();"><b>此作为电子邮件发?/b></a></p></td></tr>'); //--> </script> <tr valign="top"> <td width="8"> <img height="1" alt="" src="http://www.ibm.com/i/c.gif" width="8" /> </td> <td width="16"> <img height="16" alt="此作为电子邮件发? src="http://www.ibm.com/i/v14/icons/em.gif" width="16" vspace="3" /> </td> <td width="122"> <p> <a class="smallplainlink" href="javascript:document.email.submit();"> <b> <font color="#5c81a7" size="2">此作为电子邮件发?/font> </b> </a> </p> </td> </tr> <noscript> <tr valign="top"> <td width="8"> <img height="1" alt="" src="http://www.ibm.com/i/c.gif" width="8" /> </td> <td width="16"> <img height="16" alt="" src="http://www.ibm.com/i/c.gif" width="16" /> </td> <td class="small" width="122"> <p> <span id="ztpztjz" class="ast">未显C需?JavaScript 的文档选项</span> </p> </td> </tr> </noscript> </form> </tbody> </table> </td> </tr> </tbody> </table> <!--START RESERVED FOR FUTURE USE INCLUDE FILES--> <!-- this content will be automatically generated across all content areas --> <!--END RESERVED FOR FUTURE USE INCLUDE FILES--> <br /> </td> </tr> </tbody> </table> <p>U别Q?初</p> <p> <a > <font color="#996699">唐新?/font> </a>(<a href="mailto:xhsmart@263.net?subject=QT的信号与槽机制介l?amp;cc=xhsmart@263.net"><font color="#5c81a7">xhsmart@263.net</font></a>), 软g工程?br /></p> <p>2001 q?6 ?01 ?/p> <blockquote>信号与槽作ؓQT的核心机制在QT~程中有着q泛的应用,本文介绍了信号与槽的一些基本概c元对象工具以及在实际用过E中应注意的一些问题?/blockquote> <!--START RESERVED FOR FUTURE USE INCLUDE FILES--> <!-- include java script once we verify teams wants to use this and it will work on dbcs and cyrillic characters --> <!--END RESERVED FOR FUTURE USE INCLUDE FILES--> <p>QT是一个跨q_的C++ GUI应用构架Q它提供了丰富的H口部g集,h面向对象、易于扩展、真正的lg~程{特点,更ؓ引h注目的是目前Linux上最为流行的KDE桌面环境是建立在QT库的基础之上。QT支持下列q_QMS/WINDOWS-95?8、NT?000QUNIX/X11-Linux、Sun Solaris、HP-UX、Digital Unix、IBM AIX、SGI IRIXQEMBEDDED-支持framebuffer的Linuxq_。伴随着KDE的快速发展和普及QQT很可能成为LinuxH口q_上进行Y件开发时的GUI首选?/p> <p> <a name="1"> <span id="htvhtjz" class="atitle">概述</span> </a> </p> <p> </p> <p>信号和槽机制是QT的核心机Ӟ要精通QT~程必d信号和槽有所了解。信号和槽是一U高U接口,应用于对象之间的通信Q它是QT的核心特性,也是QT区别于其它工具包的重要地斏V信号和槽是QT自行定义的一U通信机制Q它独立于标准的C/C++语言Q因此要正确的处理信号和槽,必须借助一个称为mocQMeta Object CompilerQ的QT工具Q该工具是一个C++预处理程序,它ؓ高层ơ的事g处理自动生成所需要的附加代码?/p> <p>在我们所熟知的很多GUI工具包中Q窗口小部g(widget)都有一个回调函数用于响应它们能触发的每个动作,q个回调函数通常是一个指向某个函数的指针。但是,在QT中信号和槽取代了q些凌ؕ的函数指针,使得我们~写q些通信E序更ؓz明了?信号和槽能携带Q意数量和Lcd的参敎ͼ他们是类型完全安全的Q不会像回调函数那样产生core dumps?/p> <p>所有从QObject或其子类(例如Qwidget)z的类都能够包含信号和槽。当对象改变其状态时Q信号就p对象发射(emit)出去Q这是对象所要做的全部事情,它不知道另一端是谁在接收q个信号。这是真正的信息封装,它确保对象被当作一个真正的软glg来用。槽用于接收信号Q但它们是普通的对象成员函数。一个槽q不知道是否有Q何信号与自己相连接。而且Q对象ƈ不了解具体的通信机制?/p> <p>你可以将很多信号与单个的槽进行连接,也可以将单个的信号与很多的槽q行q接Q甚至于一个信号与另外一个信Lq接也是可能的,q时无论W一个信号什么时候发系l都立d第二个信号。MQ信号与槽构造了一个强大的部g~程机制?/p> <br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="38"> <tbody sizcache="1" sizset="38"> <tr> <td> <img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" /> <br /> <img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" /> </td> </tr> </tbody> </table> <table class="no-print" cellspacing="0" cellpadding="0" align="right" sizcache="2" sizset="39"> <tbody sizcache="2" sizset="40"> <tr align="right" sizcache="2" sizset="40"> <td sizcache="2" sizset="40"> <img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" /> <br /> <table cellspacing="0" cellpadding="0" border="0" sizcache="2" sizset="40"> <tbody sizcache="1" sizset="40"> <tr> <td valign="center"> <img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" /> <br /> </td> <td valign="top" align="right"> <a class="fbox" > <b> <font color="#996699">回页?/font> </b> </a> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="2"> <span id="bvhbdbr" class="atitle">信号</span> </a> </p> <p> </p> <p>当某个信号对其客h所有者发生的内部状态发生改变,信号被一个对象发。只?定义q这个信Lcd其派生类能够发射q个信号。当一个信可发射Ӟ与其相关联的槽将被立L行,p一个正常的函数调用一栗信?槽机制完全独立于MGUI事g循环。只有当所有的槽返回以后发函敎ͼemitQ才q回?如果存在多个槽与某个信号相关联,那么Q当q个信号被发时Q这些槽会一个接一个地 执行Q但是它们执行的序会是随机的、不定的,我们不能Zؓ地指定哪个先执行、哪 个后执行?/p> <p>信号的声明是在头文g中进行的QQT的signals关键字指入了信号声明区,随后卛_ 声明自己的信受例如,下面定义了三个信P</p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="41"> <tbody sizcache="1" sizset="41"> <tr> <td class="code-outline"> <pre class="displaycode"> signals: void mySignal(); void mySignal(int x); void mySignalParam(int x,int y);</pre> </td> </tr> </tbody> </table> <br /> <p>在上面的定义中,signals是QT的关键字Q而非C/C++的。接下来的一行void mySignal() 定义了信号mySignalQ这个信h有携带参敎ͼ接下来的一行void mySignal(int x)定义 了重名信号mySignalQ但是它携带一个整形参敎ͼq有点类gC++中的虚函数。从形式?讲信L声明与普通的C++函数是一LQ但是信号却没有函数体定义,另外Q信Lq回 cd都是voidQ不要指望能从信可回什么有用信息?/p> <p>信号由moc自动产生Q它们不应该?cpp文g中实现?/p> <br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="42"> <tbody sizcache="1" sizset="42"> <tr> <td> <img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" /> <br /> <img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" /> </td> </tr> </tbody> </table> <table class="no-print" cellspacing="0" cellpadding="0" align="right" sizcache="2" sizset="43"> <tbody sizcache="2" sizset="44"> <tr align="right" sizcache="2" sizset="44"> <td sizcache="2" sizset="44"> <img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" /> <br /> <table cellspacing="0" cellpadding="0" border="0" sizcache="2" sizset="44"> <tbody sizcache="1" sizset="44"> <tr> <td valign="center"> <img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" /> <br /> </td> <td valign="top" align="right"> <a class="fbox" > <b> <font color="#996699">回页?/font> </b> </a> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="3"> <span id="rtnxtpn" class="atitle">?/span> </a> </p> <p> </p> <p>槽是普通的C++成员函数Q可以被正常调用Q它们唯一的特D性就是很多信号可以与其相兌。当与其兌的信可发射Ӟq个槽就会被调用。槽可以有参敎ͼ但槽的参C能有~省倹{?/p> <p>既然槽是普通的成员函数Q因此与其它的函CP它们也有存取权限。槽的存取权限决定了谁能够与其相兌。同普通的C++成员函数一P槽函C分ؓ三种cdQ即public slots、private slots和protected slots?/p> <ul> <li>public slotsQ在q个区内声明的槽意味着M对象都可信号与之相q接。这对于lg~程非常有用Q你可以创徏彼此互不了解的对象,它们的信号与槽q行q接以便信息能够正确的传递? </li> <li>protected slotsQ在q个区内声明的槽意味着当前cd其子cd以将信号与之相连接。这适用于那些槽Q它们是cd现的一部分Q但是其界面接口却面向外部? </li> <li>private slotsQ在q个区内声明的槽意味着只有c自己可以将信号与之相连接。这适用于联p非常紧密的cR?</li> </ul> <p>槽也能够声明函数Q这也是非常有用的?/p> <p>槽的声明也是在头文g中进行的。例如,下面声明了三个槽Q?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="45"> <tbody sizcache="1" sizset="45"> <tr> <td class="code-outline"> <pre class="displaycode"> public slots: void mySlot(); void mySlot(int x); void mySignalParam(int x,int y);</pre> </td> </tr> </tbody> </table> <br /> <br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="46"> <tbody sizcache="1" sizset="46"> <tr> <td> <img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" /> <br /> <img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" /> </td> </tr> </tbody> </table> <table class="no-print" cellspacing="0" cellpadding="0" align="right" sizcache="2" sizset="47"> <tbody sizcache="2" sizset="48"> <tr align="right" sizcache="2" sizset="48"> <td sizcache="2" sizset="48"> <img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" /> <br /> <table cellspacing="0" cellpadding="0" border="0" sizcache="2" sizset="48"> <tbody sizcache="1" sizset="48"> <tr> <td valign="center"> <img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" /> <br /> </td> <td valign="top" align="right"> <a class="fbox" > <b> <font color="#996699">回页?/font> </b> </a> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="4"> <span id="llhzltr" class="atitle">信号与槽的关?/span> </a> </p> <p> </p> <p>通过调用QObject对象的connect函数来将某个对象的信号与另外一个对象的槽函数相兌Q这样当发射者发信hQ接收者的槽函数将被调用。该函数的定义如下:</p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="49"> <tbody sizcache="1" sizset="49"> <tr> <td class="code-outline"> <pre class="displaycode"> bool QObject::connect ( const QObject * sender, const char * signal, const QObject * receiver, const char * member ) [static]</pre> </td> </tr> </tbody> </table> <br /> <p>q个函数的作用就是将发射者sender对象中的信号signal与接收者receiver中的member槽函数联pv来。当指定信号signal时必M用QT的宏SIGNAL()Q当指定槽函数时必须使用宏SLOT()。如果发者与接收者属于同一个对象的话,那么在connect调用中接收者参数可以省略?/p> <p>例如Q下面定义了两个对象Q标{֯象label和滚动条对象scrollQƈvalueChanged()信号与标{֯象的setNum()相关联,另外信号q携带了一个整形参敎ͼq样标签L昄滚动条所处位|的倹{?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="50"> <tbody sizcache="1" sizset="50"> <tr> <td class="code-outline"> <pre class="displaycode"> QLabel *label = new QLabel; QScrollBar *scroll = new QScrollBar; QObject::connect( scroll, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)) );</pre> </td> </tr> </tbody> </table> <br /> <p>一个信L臌够与另一个信L兌Q看下面的例子:</p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="51"> <tbody sizcache="1" sizset="51"> <tr> <td class="code-outline"> <pre class="displaycode"> class MyWidget : public QWidget { public: MyWidget(); ... signals: void aSignal(); ... private: ... QPushButton *aButton; }; MyWidget::MyWidget() { aButton = new QPushButton( this ); connect( aButton, SIGNAL(clicked()), SIGNAL(aSignal()) ); }</pre> </td> </tr> </tbody> </table> <br /> <p>在上面的构造函CQMyWidget创徏了一个私有的按钮aButtonQ按钮的单击事g产生的信号clicked()与另外一个信号aSignal()q行了关联。这样一来,当信号clicked()被发时Q信号aSignal()也接着被发。当Ӟ你也可以直接单M件与某个U有的槽函数相关联,然后在槽中发aSignal()信号Q这L话似乎有点多余?/p> <p>当信号与槽没有必要l保持关联时Q我们可以用disconnect函数来断开q接。其定义如下Q?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="52"> <tbody sizcache="1" sizset="52"> <tr> <td class="code-outline"> <pre class="displaycode"> bool QObject::disconnect ( const QObject * sender, const char * signal, const Object * receiver, const char * member ) [static]</pre> </td> </tr> </tbody> </table> <br /> <p>q个函数断开发射者中的信号与接收者中的槽函数之间的关联?/p> <p>有三U情况必M用disconnect()函数Q?/p> <ul sizcache="2" sizset="53"> <li sizcache="2" sizset="53"> <p>断开与某个对象相兌的Q何对象。这g有点不可理解Q事实上Q当我们在某个对象中定义了一个或者多个信Pq些信号与另外若q个对象中的槽相兌Q如果我们要切断q些兌的话Q就可以利用q个ҎQ非怹z?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="53"> <tbody sizcache="1" sizset="53"> <tr> <td class="code-outline"> <pre class="displaycode">disconnect( myObject, 0, 0, 0 ) 或? myObject->disconnect()</pre> </td> </tr> </tbody> </table> <br /> </li> <li sizcache="2" sizset="54"> <p>断开与某个特定信LM兌?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="54"> <tbody sizcache="1" sizset="54"> <tr> <td class="code-outline"> <pre class="displaycode">disconnect( myObject, SIGNAL(mySignal()), 0, 0 ) 或? myObject->disconnect( SIGNAL(mySignal()) )</pre> </td> </tr> </tbody> </table> <br /> </li> <li sizcache="2" sizset="55"> <p>断开两个对象之间的关联?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="55"> <tbody sizcache="1" sizset="55"> <tr> <td class="code-outline"> <pre class="displaycode">disconnect( myObject, 0, myReceiver, 0 ) 或? myObject->disconnect( myReceiver )</pre> </td> </tr> </tbody> </table> <br /> </li> </ul> <p>在disconnect函数?可以用作一个通配W,分别表示M信号、Q何接收对象、接收对象中的Q何槽函数。但是发者sender不能?Q其它三个参数的值可以等??/p> <br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="56"> <tbody sizcache="1" sizset="56"> <tr> <td> <img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" /> <br /> <img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" /> </td> </tr> </tbody> </table> <table class="no-print" cellspacing="0" cellpadding="0" align="right" sizcache="2" sizset="57"> <tbody sizcache="2" sizset="58"> <tr align="right" sizcache="2" sizset="58"> <td sizcache="2" sizset="58"> <img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" /> <br /> <table cellspacing="0" cellpadding="0" border="0" sizcache="2" sizset="58"> <tbody sizcache="1" sizset="58"> <tr> <td valign="center"> <img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" /> <br /> </td> <td valign="top" align="right"> <a class="fbox" > <b> <font color="#996699">回页?/font> </b> </a> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="5"> <span id="vprnhvd" class="atitle">元对象工?/span> </a> </p> <p> </p> <p>元对象编译器mocQmeta object compilerQ对C++文g中的cd明进行分析ƈ产生用于初始化元对象的C++代码Q元对象包含全部信号和槽的名字以及指向这些函数的指针?/p> <p>moc读C++源文Ӟ如果发现有Q_OBJECT宏声明的c,它就会生成另外一个C++源文Ӟq个新生成的文g中包含有该类的元对象代码。例如,假设我们有一个头文gmysignal.hQ在q个文g中包含有信号或槽的声明,那么在编译之?moc 工具׃Ҏ该文件自动生成一个名为mysignal.moc.h的C++源文件ƈ其提交l编译器Q类似地Q对应于mysignal.cpp文gmoc工具自动生成一个名为mysignal.moc.cpp文g提交l编译器?/p> <p>元对象代码是signal/slot机制所必须的。用moc产生的C++源文件必McdC赯行编译和q接Q或者用#include语句其包含到类的源文g中。mocq不扩展#include或?define宏定?它只是简单的跌所遇到的Q何预处理指o?/p> <br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="59"> <tbody sizcache="1" sizset="59"> <tr> <td> <img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" /> <br /> <img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" /> </td> </tr> </tbody> </table> <table class="no-print" cellspacing="0" cellpadding="0" align="right" sizcache="2" sizset="60"> <tbody sizcache="2" sizset="61"> <tr align="right" sizcache="2" sizset="61"> <td sizcache="2" sizset="61"> <img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" /> <br /> <table cellspacing="0" cellpadding="0" border="0" sizcache="2" sizset="61"> <tbody sizcache="1" sizset="61"> <tr> <td valign="center"> <img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" /> <br /> </td> <td valign="top" align="right"> <a class="fbox" > <b> <font color="#996699">回页?/font> </b> </a> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="6"> <span id="ztdnrxv" class="atitle">E序样例</span> </a> </p> <p> </p> <p>q里l出了一个简单的样例E序Q程序中定义了三个信受三个槽函数Q然后将信号与槽q行了关联,每个槽函数只是简单的弹出一个对话框H口。读者可以用kdevelop生成一个简单的QT应用E序Q然后将下面的代码添加到相应的程序中厅R?/p> <p>信号和槽函数的声明一般位于头文g中,同时在类声明的开始位|必d上Q_OBJECT语句Q这条语句是不可~少的,它将告诉~译器在~译之前必须先应用moc工具q行扩展。关键字signals指出随后开始信L声明Q这里signals用的是复数Ş式而非单数Qsiganls没有public、private、protected{属性,q点不同于slots。另外,signals、slots关键字是QT自己定义的,不是C++中的关键字?/p> <p>信号的声明类g函数的声明而非变量的声明,左边要有cdQ右边要有括P如果要向槽中传递参数的话,在括号中指定每个形式参数的类型,当然QŞ式参数的个数可以多于一个?/p> <p>关键字slots指出随后开始槽的声明,q里slots用的也是复数形式?/p> <p>槽的声明与普通函数的声明一P可以携带零或多个形式参数。既然信L声明cM于普通C++函数的声明,那么Q信号也可采用C++中虚函数的Ş式进行声明,卛_名但参数不同。例如,W一ơ定义的void mySignal()没有带参敎ͼ而第二次定义的却带有参数Q从q里我们可以看到QT的信h制是非常灉|的?/p> <p>信号与槽之间的联pdM先用connect函数q行指定。如果要断开二者之间的联系Q可以用函数disconnect?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="62"> <tbody sizcache="1" sizset="62"> <tr> <td class="code-outline"> <pre class="displaycode"> //tsignal.h ... class TsignalApp:public QMainWindow { Q_OBJECT ... //信号声明? signals: //声明信号mySignal() void mySignal(); //声明信号mySignal(int) void mySignal(int x); //声明信号mySignalParam(int,int) void mySignalParam(int x,int y); //槽声明区 public slots: //声明槽函数mySlot() void mySlot(); //声明槽函数mySlot(int) void mySlot(int x); //声明槽函数mySignalParam (intQint) void mySignalParam(int x,int y); } ... //tsignal.cpp ... TsignalApp::TsignalApp() { ... //信号mySignal()与槽mySlot()相关? connect(this,SIGNAL(mySignal()),SLOT(mySlot())); //信号mySignal(int)与槽mySlot(int)相关? connect(this,SIGNAL(mySignal(int)),SLOT(mySlot(int))); //信号mySignalParam(int,int)与槽mySlotParam(int,int)相关? connect(this,SIGNAL(mySignalParam(int,int)),SLOT(mySlotParam(int,int))); } // 定义槽函数mySlot() void TsignalApp::mySlot() { QMessageBox::about(this,"Tsignal", "This is a signal/slot sample without parameter."); } // 定义槽函数mySlot(int) void TsignalApp::mySlot(int x) { QMessageBox::about(this,"Tsignal", "This is a signal/slot sample with one parameter."); } // 定义槽函数mySlotParam(int,int) void TsignalApp::mySlotParam(int x,int y) { char s[256]; sprintf(s,"x:%d y:%d",x,y); QMessageBox::about(this,"Tsignal", s); } void TsignalApp::slotFileNew() { //发射信号mySignal() emit mySignal(); //发射信号mySignal(int) emit mySignal(5); //发射信号mySignalParam(5Q?00) emit mySignalParam(5,100); }</pre> </td> </tr> </tbody> </table> <br /> <br /> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="63"> <tbody sizcache="1" sizset="63"> <tr> <td> <img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" /> <br /> <img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" /> </td> </tr> </tbody> </table> <table class="no-print" cellspacing="0" cellpadding="0" align="right" sizcache="2" sizset="64"> <tbody sizcache="2" sizset="65"> <tr align="right" sizcache="2" sizset="65"> <td sizcache="2" sizset="65"> <img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" /> <br /> <table cellspacing="0" cellpadding="0" border="0" sizcache="2" sizset="65"> <tbody sizcache="1" sizset="65"> <tr> <td valign="center"> <img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" /> <br /> </td> <td valign="top" align="right"> <a class="fbox" > <b> <font color="#996699">回页?/font> </b> </a> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="7"> <span id="nxjvhnl" class="atitle">应注意的问题</span> </a> </p> <p> </p> <p>信号与槽机制是比较灵zȝQ但有些局限性我们必M解,q样在实际的使用q程中做到有的放矢,避免产生一些错误。下面就介绍一下这斚w的情c?/p> <p>1Q信号与槽的效率是非帔R的,但是同真正的回调函数比较hQ由于增加了灉|性,因此在速度上还是有所损失Q当然这U损qҎ说是比较的Q通过在一台i586-133的机器上试?0微秒Q运行LinuxQ,可见q种机制所提供的简z性、灵zL还是值得的。但如果我们要追求高效率的话Q比如在实时pȝ中就要尽可能的少用这U机制?/p> <p>2Q信号与槽机制与普通函数的调用一P如果使用不当的话Q在E序执行时也有可能生死循环。因此,在定义槽函数时一定要注意避免间接形成无限循环Q即在槽中再ơ发所接收到的同样信号。例?在前面给出的例子中如果在mySlot()槽函C加上语句emit mySignal()卛_形成d@环?/p> <p>3Q如果一个信号与多个槽相联系的话Q那么,当这个信可发射Ӟ与之相关的槽被激zȝ序是随机的?/p> <p>4. 宏定义不能用在signal和slot的参C?/p> <p>既然moc工具不扩?defineQ因此,在signals和slots中携带参数的宏就不能正确地工作,如果不带参数是可以的。例如,下面的例子中带有参数的宏SIGNEDNESS(a)作ؓ信号的参数是不合语法的:</p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="66"> <tbody sizcache="1" sizset="66"> <tr> <td class="code-outline"> <pre class="displaycode"> #ifdef ultrix #define SIGNEDNESS(a) unsigned a #else #define SIGNEDNESS(a) a #endif class Whatever : public QObject { [...] signals: void someSignal( SIGNEDNESS(a) ); [...] };</pre> </td> </tr> </tbody> </table> <br /> <p>5. 构造函C能用在signals或者slots声明区域内?/p> <p>的确Q将一个构造函数放在signals或者slots区内有点不可理解Q无论如何,不能它们放在private slots、protected slots或者public slots区内。下面的用法是不合语法要求的Q?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="67"> <tbody sizcache="1" sizset="67"> <tr> <td class="code-outline"> <pre class="displaycode"> class SomeClass : public QObject { Q_OBJECT public slots: SomeClass( QObject *parent, const char *name ) : QObject( parent, name ) {} // 在槽声明区内声明构造函C合语? [...] };</pre> </td> </tr> </tbody> </table> <br /> <p>6. 函数指针不能作ؓ信号或槽的参数?/p> <p>例如Q下面的例子中将void (*applyFunction)(QList*, void*)作ؓ参数是不合语法的Q?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="68"> <tbody sizcache="1" sizset="68"> <tr> <td class="code-outline"> <pre class="displaycode"> class someClass : public QObject { Q_OBJECT [...] public slots: void apply(void (*applyFunction)(QList*, void*), char*); // 不合语法 };</pre> </td> </tr> </tbody> </table> <br /> <p>你可以采用下面的Ҏl过q个限制Q?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="69"> <tbody sizcache="1" sizset="69"> <tr> <td class="code-outline"> <pre class="displaycode"> typedef void (*ApplyFunctionType)(QList*, void*); class someClass : public QObject { Q_OBJECT [...] public slots: void apply( ApplyFunctionType, char *); };</pre> </td> </tr> </tbody> </table> <br /> <p>7.信号与槽不能有缺省参数?/p> <p>既然signal->slotl定是发生在q行时刻Q那么,从概念上讲用缺省参数是困难的。下面的用法是不合理的:</p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="70"> <tbody sizcache="1" sizset="70"> <tr> <td class="code-outline"> <pre class="displaycode"> class SomeClass : public QObject { Q_OBJECT public slots: void someSlot(int x=100); // x的缺省值定义成100Q在槽函数声明中使用是错误的 };</pre> </td> </tr> </tbody> </table> <br /> <p>8.信号与槽也不能携带模板类参数?/p> <p>如果信受槽声明为模板类参数的话Q即使moc工具不报告错误,也不可能得到预期的结果?例如Q下面的例子中当信号发射Ӟ槽函C会被正确调用Q?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="71"> <tbody sizcache="1" sizset="71"> <tr> <td class="code-outline"> <pre class="displaycode"> [...] public slots: void MyWidget::setLocation (pair<int,int> location); [...] public signals: void MyObject::moved (pair<int,int> location);</pre> </td> </tr> </tbody> </table> <br /> <p>但是Q你可以使用typedef语句来绕q这个限制。如下所C:</p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="72"> <tbody sizcache="1" sizset="72"> <tr> <td class="code-outline"> <pre class="displaycode"> typedef pair<int,int> IntPair; [...] public slots: void MyWidget::setLocation (IntPair location); [...] public signals: void MyObject::moved (IntPair location);</pre> </td> </tr> </tbody> </table> <br /> <p>q样使用的话Q你可以得到正的l果?/p> <p>9.嵌套的类不能位于信号或槽区域内,也不能有信号或者槽?/p> <p>例如Q下面的例子中,在class B中声明槽b()是不合语法的Q在信号区内声明槽b()也是不合语法的?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="73"> <tbody sizcache="1" sizset="73"> <tr> <td class="code-outline"> <pre class="displaycode"> class A { Q_OBJECT public: class B { public slots: // 在嵌套类中声明槽不合语法 void b(); [....] }; signals: class B { // 在信号区内声明嵌套类不合语法 void b(); [....] }: };</pre> </td> </tr> </tbody> </table> <br /> <p>10.友元声明不能位于信号或者槽声明区内?/p> <p>相反Q它们应该在普通C++的private、protected或者public区内q行声明。下面的例子是不合语法规范的Q?/p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="74"> <tbody sizcache="1" sizset="74"> <tr> <td class="code-outline"> <pre class="displaycode"> class someClass : public QObject { Q_OBJECT [...] signals: //信号定义? friend class ClassTemplate; // 此处定义不合语法 };</pre> </td> </tr> </tbody> </table> <br /> <br /> <br /> <p> <a name="resources"> <span id="lxhjvtz" class="atitle">参考资?</span> </a> </p> <ul> <li> <a > <font color="#5c81a7">QT</font> </a> <br /> <br /> </li> <li> <a > <font color="#5c81a7">KDevelop</font> </a> <br /> </li> </ul> <br /> <br /> <p> <a name="author"> <span id="prtvxfd" class="atitle">关于作?/span> </a> </p> <table cellspacing="0" cellpadding="0" width="100%" border="0" sizcache="2" sizset="75"> <tbody sizcache="1" sizset="75"> <tr> <td colspan="3"> <img height="5" alt="" src="http://www.ibm.com/i/c.gif" width="100%" /> </td> </tr> <tr valign="top" align="left"> <td> <p> </p> </td> <td> <img height="5" alt="" src="http://www.ibm.com/i/c.gif" width="4" /> </td> <td width="100%"> <p>唐新?软g工程师。Email: <a href="mailto:xhsmart@263.net?cc=xhsmart@263.net"><font color="#5c81a7">xhsmart@263.net</font></a></p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <img src ="http://www.shnenglu.com/erran/aggbug/118185.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/erran/" target="_blank">erran</a> 2010-06-18 18:11 <a href="http://www.shnenglu.com/erran/archive/2010/06/18/118185.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>?VC2008 express~译QT4.5http://www.shnenglu.com/erran/archive/2010/06/18/118146.htmlerranerranFri, 18 Jun 2010 02:18:00 GMThttp://www.shnenglu.com/erran/archive/2010/06/18/118146.htmlhttp://www.shnenglu.com/erran/comments/118146.htmlhttp://www.shnenglu.com/erran/archive/2010/06/18/118146.html#Feedback0http://www.shnenglu.com/erran/comments/commentRss/118146.htmlhttp://www.shnenglu.com/erran/services/trackbacks/118146.htmlVC2008 express~译QT4.5Q{帖)
2009-11-26 15:35

原文Q?a >http://hi.baidu.com/fairysky/blog/item/883cd1b474c33c7b8bd4b219.html

最新的QT4.5发布了,增加了LGPL2.1协议Q实在是众望所归啊。。?/p>

参考资料:

1?【{贴】VC 2005 下如何编译安装ƈ开?QT 4.4.0 应用E序

2?qt4:qt~译安装信息的解?/a>

3?qt4:windows下编译qt 4.3.2

4?|友已编译好的Qt开源版下蝲(含Debug? Q主要是参考它的configure参数Q?/p>

q有QT安装目录下的?install ”文?/p>

一、下载QT4.5Q本文仅讨论LGPL/Free DownloadsQ?/strong>

下蝲地址Q?a >http://download.qtsoftware.com/qt/source/qt-win-opensource-src-4.5.0.zip

解压Q假定解压到E:\qt-win-opensource-src-4.5.0 Q解压\径不要包含空白,另外也徏议不要包含中文名UͼQ解压后目录层次Q?/p>

二、设|环境变?/strong>

set QTDIR=E:\qt-win-opensource-src-4.5.0

set path=%path%;%QTDIR%\bin

ҎQ?/strong>

“我的电脑?>“属性?>“高U?>“环境变量”,弹出一个对话框Q?/p>

然后“xxx的用户变量?>“新建”,弹出一个输入对话框Q输入:

“变量名?--- QTDIR

“变量值?--- E:\qt-win-opensource-src-4.5.0

同上Q修改path环境变量ҎQ?/strong>

在“xxx的用户变量”中选择“PATH”,然后“编辑”,在“变量值”的最后输入?;%QTDIR%\bin ”(不带引号Q注意有一个分P

三、编译QT

1、在命o行设|好vc~译器环境变量(我是通过一个简单的批处理文件来讄好vc~译器的环境变量Q?/font>

1 @echooff
2 call"C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
3
4 rem 在这里,调用sqlite3的环境变量设|批处理是因为在后来qt~译时要用到sqliteQqt需要知道sqlite的include和lib以及dll的位|?/span>
5 call"D:\环境变量批处理设|\sqlite3环境变量.bat"

q程我就不多说了Q如果有不明白的Q可以留aQ我个h认ؓ管在windows下有VS IDEQ但是作Z个编Eh员,掌握基本的命令行~译知识应该是一个基本的技能)

如果讄好了vc~译器环境变量,q行" cl/? " Q不包括引号Q,如果输出了cl.exe帮助说明信息Q则表示vc~译器环境变量设|成功?/p>

可以通过" set path "Q? set include "Q? set lib " 命o查看path、include、lib环境变量

2、配|QTQconfigureQ?/p>

在命令行讄好vc~译器环境变量之后,q入到QT解压目录Q?QTDIR%Q,然后输入" configure/? "Qconfigure位于%QTDIR%目录下)Q查看configure的帮助?/p>

下面是我的configure配置参数Q?/font>

1、编译shared版(默认~译为shared版,不需要设|)Qƈ且编译debug和release两个版本Q?font color="#3366ff">-debug-releaseQ?br />2、用vc2008Q包括express版)(-platform win32-msvc2008)
3、用qt自带的zlib、gif、libpng、libmng、libtiff、libjpeg (
-qt-zlib -qt-gif -qt-libpng -qt-libmng -qt-libtiff -qt-libjpeg )
4、编译数据库插g支持sqlite、odbcQ需要相应的C/C++头文件和库的支持Q?
-plugin-sql-sqlite -plugin-sql-odbc )
5、不支持qt3 (-no-qt3support)

其中W?条,我们已经?/font> vc~译器环境变量设|?bat q行了设|,通过

call "D:\环境变量批处理设|\sqlite3环境变量.bat"

讄了sqlite的include和lib以及dll的搜索\径(dll搜烦路径讄在path环境变量中)

附加
6、无mmx指o集支?(-no-mmx)
7、无3dnow指o集支?(-no-3dnow)
8、无sse和sse2指o集支?(-no-sse -no-sse2)
9、无direct3d支持Q我用不上direct3dQ默认不~译direct3dQ?br />10、无openssl支持 (-no-openssl)
11、无dbus支持Qdbus是一个类gIPC的实玎ͼ不过我好像用不上Q?(-no-dbus)
12、无phonon支持以及phonon向后兼容性支持(phonon是一个基于kde的多媒体支持Q?/font> q且主要是用于那些比较古老的~译器,在我的机器上不需要) Q?font color="#3366ff">-no-phonon -no-phonon-backendQ?br />13、不~译webkit模块Q类g览器的东西Q我个h不需要) Q?font color="#3366ff">-no-webkit
Q?br />14、不支持脚本工具scripttools Q?font color="#3366ff">-no-scripttools
Q?/font>

生成工程文g相关
15、无生成sln以及vcproj文gQ生成的sln文g好像不好使,不能用vc2008打开Q,只生成makefile文g Q?font color="#3366ff">-no-dsp -no-vcproj
Q?/font>

上述只是我个人的需求,大家可以Ҏ自己的需要进行调_我这么做只是Z可能的~短~译旉Q?/font>

configure -debug-and-release -platform win32-msvc2008 -qt-zlib -qt-gif -qt -libpng -qt-libmng -qt-libtiff -qt-libjpeg -plugin-sql-sqlite -plugin-sql- odbc -no-qt3support -no-mmx -no-3dnow -no-sse -no-sse2 -no-openssl -no-dbus -no-phonon -no-phonon-backend -no-webkit -no-scripttools -no-dsp -no-vcproj

configure大概需要执?~10分钟Q如果对configure产生的信息不清楚的话Q可以看看这文章(qt4:qt~译安装信息的解?/a>Q?/font>

configure.exe主要是做两g事:

1Q编译qmakeQƈ编译好的qmake.exe拯到bin目录下(q又是之前要d" %QTDIR%\bin ”到path环境变量中的原因Q?/font>

2Q生成makefile文gQ包括编译qt的makefile文g以及examples、demos、tools{的makefiles文gQ?/font>

三、编译QT

在QT的解压目录下执行nmakeQ确保configure.exeq行成功Qconfigure会在QT的解压目录下生成一个Makefile文gQ?/font>

Z~短~译旉Q我们可以现examples和demos目录转移Q例如新Z个文件夹Q然后将q?个目录移到该目录下)Q这样nmake在编译到examples和demos时会报错Q然后退出编译过E?/font>

然后是漫长的等待了~~~Q编译的时候就d点别的吧Q运动运?img src="http://img.baidu.com/hi/jx/j_0028.gif" />Q?/font>

按照我上面的操作Q编译完成qt大概需?个小Ӟ占用盘2G左右Q如果完整的~译qt、examples、demosQ,那么大概需?~6个小Ӟ占用盘10G左右 Q?/font>

四、清理收ַ?/strong>

~译完成之后Q要q行清理Q不焉么多盘被占用了Q太心疼?/font>

q行" nmake confclean "Q参? install "文gQ,q样清理完成之后Q整个qt解压目录大小Uؓ770M左右

五、编译demos

examples、demos目录Ud原位Q如果想要运行demosQ可以通过命o行进入到demos目录下(保证环境变量已设|好Q,然后q行nmakeQ又是一D|O长的旉Q?个小时左叻I

~译demos完成之后Q在qt解压目录下的bin目录中有一? qtdemo.exe "Q运?/font>

同样圎ͼ我们也要q行清理工作Q进入到demos目录Q同上,要保证环境变量已讄好)Q运? nmake clean "

q样我们p看到一部分的运行示例了Qؓ什么是部分Q因为qtdemo.exe不仅仅是包含demos目录中的例子Q同样也包含examples目录中的例子Q如果想要查看完整的qtdemo.exeQ还需要编译examplesQ方法同demosQ?/font>

最后,Qt路径d到VC~译环境中。(参见 【{贴】VC 2005 下如何编译安装ƈ开?QT 4.4.0 应用E序 Q?/strong>

工具->选项->目和解x?>VC++目录Q?/strong>

在包含文件一栏添加: E:\qt-win-opensource-src-4.5.0\include\QtGuiQE:\qt-win-opensource-src-4.5.0\include\QtCoreQE:\qt-win-opensource-src-4.5.0\include

在库文g一栏添加E:\qt-win-opensource-src-4.5.0\lib

QT安装路径d到Pathpȝ环境变量中,例如QE:\qt-win-opensource-src-4.5.0\binQ这一步可以省略,在本文的?二、设|环境变?/font> ”已l设|好了)

xQQT和vc~译环境基本上配|完成了



erran 2010-06-18 10:18 发表评论
]]>
?Qt-WinCE安装、开发及部v全解http://www.shnenglu.com/erran/archive/2010/06/18/118145.htmlerranerranFri, 18 Jun 2010 02:16:00 GMThttp://www.shnenglu.com/erran/archive/2010/06/18/118145.htmlhttp://www.shnenglu.com/erran/comments/118145.htmlhttp://www.shnenglu.com/erran/archive/2010/06/18/118145.html#Feedback0http://www.shnenglu.com/erran/comments/commentRss/118145.htmlhttp://www.shnenglu.com/erran/services/trackbacks/118145.htmlQt-WinCE安装、开发及部v全解
penguinx   发表? 2008-07-31

理提醒:
本帖?XChinux ?Qt for Embedded Linux Ud到本?2010-02-07)
Qt-WinCE 全解
声明Q?/font> p了三天时_周{各大|站Q终于在今天自qW一?/font> Qt E序在“小 I(SAMSUNG i718+) ”上跑了hQ?br />


一?/font> Qt 嵌入式环境的搭徏
a)        首先Q下?/font> Qt 的嵌入式开发包 qt-embedded-wince-opensource-src-4.4.0.zip

b)        然后Q下?/font> VS2005 ?/font>

c)        最后,下蝲一个嵌入式开发的 SDK Q如 Windows Mobile 5.0 Pocket PC SDK, 可以在微软的官方|站上下载到Q?/font>

d)        q有一个是同步的Y?/font> Microsoft ActiveSync4.5 中文体版?/font>

------------------------------------------ ?/font> ---- ?/font> ----------------------------------
e)        首先安装 VS2005 Q很单,按照向导来,在自定义安装中务必选择“智能设备开发”?/font>

f)          关于 Microsoft ActiveSync4.5 的安装更是?/font> straightforward ”。在此不再多_

g)        然后Q安?/font> Windows Mobile 或是其它版本?/font> SDK Q可以用自定义的 SDK! ?/font>

h)        比较ȝ的就?/font> qt-embedded-wince 的安装。参照下面的步骤Q①、解压,解压后的文件夹攑ֈ一个不含空格的路径中,如我的: f:\penguinx\qt_wince Q?/font> qt_wince 即ؓ此文件夹。然后设|环境变量:右键“我的电脑”- > “属性”- > 点“高U”标{- > “环境变量”选项Q?/font> > ?/font> "PATH" 中添加\径?/font> f:\penguinx\qt_wince \ bin ”?/font> OK Q②~译前戏。首先,配置~译选项Q进?/font> VS2005 的命令行中,q入解压的文件夹Q然后执行如下: configure -platform win32-msvc2005 -xplatform wince50standard-armv4i-msvc2005 可以Ҏ自己的板子及手机配置来选择其它的嵌入式?/font> xplatfrom 。这个过E可能需要十几分钟。执行完后,再次?/font> VS2005 中设|时的环境变量Q编译时要用刎ͼ如下Q?/font>

      set INCLUDE=D:\Program Files\Microsoft Visual Studio 8\VC\ce\include;D:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket PC SDK\Include\Armv4i



      set LIB=D:\Program Files\Microsoft Visual Studio 8\VC\ce\lib\armv4i;D:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket PC SDK\Lib\ARMV4I



      set PATH=D:\Program Files\Microsoft Visual Studio 8\VC\ce\bin\x86_arm;%PATH%

              在此我期望能Ҏ自己的Y件安装情况将上面的目录“拿来主义”一下。设 |完后,执行 nmake Q过两、三个钟头后Q你可?/font> Enjoy your journey.
最后,执行nmakeQ安装完毕!我的Qt-WinCE安装在  f:\penguinx\qt_wince



二、编译Qt-WinCEE序
命o行法 ( 不用 IDE) Q?/font>

首先、用 VS2005 命o行进入要~译的程序目?/font> ( 此目录最好就在安装目?/font> f:\penguinx\qt_wince ?/font> ) Q执?/font> < f:\penguinx\qt_wince >bin\qmake.exe –project –o example.pro  其中Q?/font> Install Qt Path Z?/font> Qt-WinCE 的安装目录。这个时候,可以产生 example.pro 文g?/font>

然后、就是?/font> Makefile 的时候:?/font> VS2005 命o行下输入Q?/font>

f:\penguinx\qt_wince\bin\qmake -spec ..\mkspecs\wince50standard-armv4i-msvc2005 -win32 -o Makefile example.pro 此时Q恭喜你Q?/font> Makefile 文g已经产生?/font>

      最后,是?/font> nmake 来编译和链接E序了。先安装时的环境变?/font> ( 三个 set) 在当?/font> VS2005 命o行下重新执行一遍。否则会出现如下错误Q?/font>

cl: 命o?/font> warning D9002 : 忽略未知选项?/font> -QRarch4T ?/font>

cl: 命o?/font> warning D9002 : 忽略未知选项?/font> -QRinterwork-return ?/font>

main.cpp

mainwindow.cpp

f:\penguinx\qt_wince\include\qtgui\../../src/gui/widgets/qmenu.h(144) : error C2

146: 语法错误 : ~少?/font> ; ?/font> ( 在标识符?/font> wceMenu ”的前面 )

f:\penguinx\qt_wince\include\qtgui\../../src/gui/widgets/qmenu.h(144) : error C4

430: ~少cd说明W?/font> - 假定?/font> int 。注?/font> : C++ 不支持默?/font> int

f:\penguinx\qt_wince\include\qtgui\../../src/gui/widgets/qmenu.h(144) : error C4

430: ~少cd说明W?/font> - 假定?/font> int 。注?/font> : C++ 不支持默?/font> int

f:\penguinx\qt_wince\include\qtgui\../../src/gui/widgets/qmenu.h(144) : warning

C4183: ?/font> wceMenu ?/font> : ~少q回cdQ假定ؓq回?/font> int ”的成员函数?/font>

然后Q执?/font> nmake Q看着一行的白银失完后Q就是金?/font> ( 你的 exe 文g ) 了?/font>

注意Q在执行 nmake 的时候,可能会看到如下错误信息:

        link /LIBPATH:"f:\penguinx\qt_wince\lib" /LIBPATH:"f:\penguinx\qt_wince\

lib" /NOLOGO /NODEFAULTLIB:OLDNAMES.LIB /DEBUG /SUBSYSTEM:WINDOWSCE,5.00 /MACHIN

E:THUMB /OUT:debug\node.exe @C:\DOCUME~1\User\LOCALS~1\Temp\nm6B3.tmp

tmp\obj\debug_shared\main.obj : fatal error LNK1112: 模块计算机类型?/font> X 86 ?/font> 与目?/font>

计算机类型?/font> THUMB ”冲H?/font>

NMAKE : fatal error U1077: ?D:\Program Files\Microsoft Visual Studio 8\VC\ce\b

in\x86_arm\link.EXE" ?/font> : q回代码?/font> 0x 458 ?/font>

      q种错误搞的我很无奈Q我不执?/font> nmake Q直接执?/font> nmake release 没有这U错误?q种错误可能是因为“环境变量”中?/font> PATH ”中讄了?/font> f:\penguinx\qt_wince\bin ”。在我把q个变量L后,重新打开 VS2005 命o?/font> ( 因ؓ得重新读?/font> PATH 变量 ) 。然后按照上面的步骤做下来,最后用 nmake 重新执行一遍,很好很流畅!

三?/font> Qt –WinCE E序的部|Ԍ非打包)
      可以直接把上面开发的 *.exe 文g和其需要的 *.dll 一?/font> CP C个目录中Q这?/font> dll 一般有Q?/font>

D:\Program Files\Microsoft Visual Studio 8\VC\ce\Dll\armv4i\ msvcr80.dll

F:\penguinx\wince_vs2005\lib\ QtCore4.dll

F:\penguinx\wince_vs2005\lib\QtGui4.dll

其它的根据自己项目的需?/font> CP 下,p了?/font>

      如果惛_E序部v?/font> *.cab 形式的,在上面的“解x案”中Q点“文件”- > “新建”- > “项目”- > 点“其它”,其中有关于智能设备部|的Q就它了 ( 我在实验室机子上开发的Q回来写手记Q所以具体的操作记的不是非常清楚Q将! ) 。根据向导徏立后Q在新徏?/font> cab 目中点“属性”,最后,生成p了?/font> CP 到板子就可以q行了?/font>

注意Q所有的 CP 都是?/font> ActiveSync 软g通过 USB 传输的,当然可以用其它传输手D,最l能上板子就行?/font>

-Zm200 -w34100 -w34189 -Zm200 -w34100 -w34189 -w34100 -w34189

注意?/font> WinCE 部v时的版本Q如果设备上?/font> WinCE 版本比开发用的版本低的话Q将昄?/font> ****, 需要更新的 Windows 版本”云云?/font>

/SUBSYSTEM:WINDOWSCE,5.00 /MACHINE:THUMB

/SUBSYSTEM:WINDOWSCE,5.00 /MACHINE:THUMB





erran 2010-06-18 10:16 发表评论
]]>
޷?Vþò| Ļһþ| þùƷ| һĻþ| ĻۺϾþò| av˾þۺɫ| þþþһ| ޹˾þһWWW| þþŮ붯ȺëƬ | Ʒþ| ԾþþӰԺ| þ㽶ۺɫһۺɫ88| 69Ʒþþþùۿ| þۺŷ| ˳˳ۺþþ | һһþaþۺϾƷ һһþۺϺݺ | ŷ㽶þۺվ| ɫۺϾþ| þþɫۺϾɫ99| þþžžƷ99Ʒ| 99þۺϹƷ | Ʒþþþa| һձȾþۺ| 91Ʒ91þۺ| þ99ֻоƷ| þһŷպ| ƷŮͬһþ| 777þþƷһ| 97þó˾Ʒվ| þwwƷw˳| ˾þô߽AVɫɫ | þþùƷ| 99þһ| ɫۺϾþþþ| һĻþ| ƷۺרƬþþ | ƷþþþþҰ| 97þ㽶߿ۿ| þùƷ-Ʒ| AVɫۺϾþAVɫۺ | þ99Ʒ99þ6|