﻿<?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++博客-RTY 实践出真知-随笔分类-QML</title><link>http://www.cppblog.com/lauer3912/category/17482.html</link><description>没有理由不学习</description><language>zh-cn</language><lastBuildDate>Sun, 24 Feb 2013 00:16:31 GMT</lastBuildDate><pubDate>Sun, 24 Feb 2013 00:16:31 GMT</pubDate><ttl>60</ttl><item><title>QML 中调用本地标准的对话框如：QFileDialog  QFontDialog  Google搜索关键字qml qfiledialog (Qt5)</title><link>http://www.cppblog.com/lauer3912/archive/2012/10/06/192893.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 06 Oct 2012 00:10:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/10/06/192893.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/192893.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/10/06/192893.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/192893.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/192893.html</trackback:ping><description><![CDATA[其实最为重要的一点，就是App的类型：<div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;">Qt5 中包括：</div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;">QObject -&gt;&nbsp;<span style="font-size: 14px; ">QCoreApplication -&gt;&nbsp;QGuiApplication -&gt;&nbsp;QApplication</span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px; "><br /></span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px; ">一般，QML的程序使用</span><span style="font-size: 14px;">QGuiApplication，如果使用QGuiApplication的话，那么QtWidget的相关类就不能运行正常了。</span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px;">需要使用QApplication类来处理，这样，QtWidget的相关类就可以使用了。</span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px; ">特别是我们对标准对话框（QFileDialog\ QFontDialog \ QColorDialog）等等</span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px; "><br /></span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px; "><br /></span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px; ">下面上代码：</span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px; "><br /></span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px; "><br /></span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px; ">main.cpp</span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><span style="font-size: 14px; ">=====================================================================</span></div><div style="font-family: 'Courier New'; font-size: 12px; line-height: normal;"><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="display: inline-block; color: #55ffff; background-color: silver;">//![0]</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #5555ff; ">#include</span> <span style="color: #ff55ff; ">"piechart.h"</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #5555ff; ">#include</span> <span style="color: #ff55ff; ">&lt;QtQuick/QQuickView&gt;</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #5555ff; ">#include</span> <span style="color: #ff55ff; ">&lt;QGuiApplication&gt;</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #5555ff; ">#include</span> <span style="color: #ff55ff; ">&lt;QApplication&gt;</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #ffff55; ">int</span> main<span style="color: #aaaaaa; ">(</span><span style="color: #ffff55; ">int</span> argc<span style="color: #aaaaaa; ">,</span> <span style="color: #ffff55; ">char</span> <span style="color: #aaaaaa; ">*</span>argv<span style="color: #aaaaaa; ">[])</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="display: inline-block; color: #aaaaaa; background-color: silver;">{</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "> QApplication app<span style="color: #aaaaaa; ">(</span>argc<span style="color: #aaaaaa; ">,</span> argv<span style="color: #aaaaaa; ">);</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre><pre style="margin-top: 0px; margin-bottom: 0px; "> qmlRegisterType<span style="color: #aaaaaa; ">&lt;</span><span style="color: #55ff55; ">PieChart</span><span style="color: #aaaaaa; ">&gt;(</span><span style="color: #ff55ff; ">"Charts"</span><span style="color: #aaaaaa; ">,</span> <span style="color: #ff55ff; ">1</span><span style="color: #aaaaaa; ">,</span> <span style="color: #ff55ff; ">0</span><span style="color: #aaaaaa; ">,</span> <span style="color: #ff55ff; ">"PieChart"</span><span style="color: #aaaaaa; ">);</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre><pre style="margin-top: 0px; margin-bottom: 0px; "> QQuickView view<span style="color: #aaaaaa; ">;</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "> view<span style="color: #aaaaaa; ">.</span>setResizeMode<span style="color: #aaaaaa; ">(</span>QQuickView<span style="color: #aaaaaa; ">::</span>SizeRootObjectToView<span style="color: #aaaaaa; ">);</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "> view<span style="color: #aaaaaa; ">.</span>setSource<span style="color: #aaaaaa; ">(</span>QUrl<span style="color: #aaaaaa; ">::</span>fromLocalFile<span style="color: #aaaaaa; ">(</span><span style="color: #ff55ff; ">"app.qml"</span><span style="color: #aaaaaa; ">));</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "> view<span style="color: #aaaaaa; ">.</span>show<span style="color: #aaaaaa; ">();</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #ffff55; ">return</span> app<span style="color: #aaaaaa; ">.</span>exec<span style="color: #aaaaaa; ">();</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="display: inline-block; color: #aaaaaa; background-color: silver;">}</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="display: inline-block; color: #55ffff; background-color: silver;">//![0]</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #55ffff;"><br /></span></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #55ffff;">=======================================================================================</span></pre><pre style="margin-top: 0px; margin-bottom: 0px; ">PieChart.h</pre><pre style="margin-top: 0px; margin-bottom: 0px; ">=======================================================================================</pre><pre style="margin-top: 0px; margin-bottom: 0px; "><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #000080; ">#ifndef</span> PIECHART_H</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #000080; ">#define</span> PIECHART_H</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #000080; ">#include</span> <span style="color: #008000; ">&lt;QtQuick/QQuickPaintedItem&gt;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #000080; ">#include</span> <span style="color: #008000; ">&lt;QColor&gt;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #008000; ">//![0]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #808000; ">class</span> <span style="color: #800080; ">PieChart</span> : <span style="color: #808000; ">public</span> QQuickPaintedItem</pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">{</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #008000; ">//![0]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800080; ">Q_OBJECT</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800080; ">Q_PROPERTY</span>(QString name READ name WRITE setName)</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800080; ">Q_PROPERTY</span>(QColor color READ color WRITE setColor)</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #008000; ">//![1]</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: #008000; ">//![1]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800080; ">PieChart</span>(QQuickItem *parent = <span style="color: #000080; ">0</span>);</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> QString name() <span style="color: #808000; ">const</span>;</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #808000; ">void</span> setName(<span style="color: #808000; ">const</span> QString &amp;name);</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> QColor color() <span style="color: #808000; ">const</span>;</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #808000; ">void</span> setColor(<span style="color: #808000; ">const</span> QColor &amp;color);</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #808000; ">void</span> paint(QPainter *painter);</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #008000; ">//![2]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800080; ">Q_INVOKABLE</span> <span style="color: #808000; ">void</span> clearChart();</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #808000; ">signals</span>:</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #808000; ">void</span> chartCleared();</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #008000; ">//![2]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #808000; ">private</span>:</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> QString <span style="color: #800000; ">m_name</span>;</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> QColor <span style="color: #800000; ">m_color</span>;</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #008000; ">//![3]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">};</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #008000; ">//![3]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #000080; ">#endif</span></pre></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre><pre style="margin-top: 0px; margin-bottom: 0px; ">========================================================================================</pre><pre style="margin-top: 0px; margin-bottom: 0px; ">PieChart.cpp</pre><pre style="margin-top: 0px; margin-bottom: 0px; ">========================================================================================</pre><pre style="margin-top: 0px; margin-bottom: 0px; "><pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #000080; ">#include</span> <span style="color: #008000; ">"piechart.h"</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #000080; ">#include</span> <span style="color: #008000; ">&lt;QPainter&gt;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #000080; ">#include</span> <span style="color: #008000; ">&lt;QFileDialog&gt;</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #800080; ">PieChart</span>::<span style="color: #800080; ">PieChart</span>(QQuickItem *parent)</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> : QQuickPaintedItem(parent)</pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">{</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; ">QString <span style="color: #800080; ">PieChart</span>::name() <span style="color: #808000; ">const</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">{</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #808000; ">return</span> <span style="color: #800000; ">m_name</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: #808000; ">void</span> <span style="color: #800080; ">PieChart</span>::setName(<span style="color: #808000; ">const</span> QString &amp;name)</pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">{</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">m_name</span> = name;</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; ">QColor <span style="color: #800080; ">PieChart</span>::color() <span style="color: #808000; ">const</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">{</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #808000; ">return</span> <span style="color: #800000; ">m_color</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: #808000; ">void</span> <span style="color: #800080; ">PieChart</span>::setColor(<span style="color: #808000; ">const</span> QColor &amp;color)</pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">{</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">m_color</span> = color;</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: #808000; ">void</span> <span style="color: #800080; ">PieChart</span>::paint(QPainter *painter)</pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">{</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> QPen pen(<span style="color: #800000; ">m_color</span>, <span style="color: #000080; ">2</span>);</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> painter-&gt;setPen(pen);</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> painter-&gt;setRenderHints(QPainter::HighQualityAntialiasing, <span style="color: #808000; ">true</span>);</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> painter-&gt;drawPie(boundingRect(), <span style="color: #000080; ">90</span> * <span style="color: #000080; ">16</span>, <span style="color: #000080; ">290</span> * <span style="color: #000080; ">16</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: #008000; ">//![0]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #808000; ">void</span> <span style="color: #800080; ">PieChart</span>::clearChart()</pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">{</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> QString fileName = QFileDialog::getOpenFileName(<span style="color: #000080; ">0</span>,</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> tr(<span style="color: #008000; ">"Open Image"</span>), <span style="color: #008000; ">""</span>, tr(<span style="color: #008000; ">"Image Files (*.png *.jpg *.bmp)"</span>));</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> setColor(QColor(Qt::transparent));</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> update();</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #808000; ">emit</span> chartCleared();</pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">}</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #008000; ">//![0]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre><pre style="margin-top: 0px; margin-bottom: 0px; ">========================================================================================</pre><pre style="margin-top: 0px; margin-bottom: 0px; ">app.qml</pre><pre style="margin-top: 0px; margin-bottom: 0px; ">========================================================================================</pre><pre style="margin-top: 0px; margin-bottom: 0px; "> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #008000; ">//![0]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #808000; ">import</span> Charts 1.0</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #808000; ">import</span> QtQuick 2.0</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #800080; ">Item</span> {</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">width</span>: 300; <span style="color: #800000; ">height</span>: 200</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800080; ">PieChart</span> {</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">id</span>: <span style="font-style: italic; ">aPieChart</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">anchors.centerIn</span>: <span style="font-style: italic; ">parent</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">width</span>: 100; <span style="color: #800000; ">height</span>: 100</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">color</span>: <span style="color: #008000; ">"red"</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">onChartCleared</span>: <span style="font-style: italic; color: #0055af; ">console</span>.log(<span style="color: #008000; ">"The</span> <span style="color: #008000; ">chart</span> <span style="color: #008000; ">has</span> <span style="color: #008000; ">been</span> <span style="color: #008000; ">cleared"</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: #800080; ">MouseArea</span> {</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">anchors.fill</span>: <span style="font-style: italic; ">parent</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">onClicked</span>: <span style="font-style: italic; ">aPieChart</span>.clearChart()</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: #800080; ">Text</span> {</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">anchors</span> { <span style="color: #800000; ">bottom</span>: <span style="font-style: italic; ">parent</span>.bottom; <span style="color: #800000; ">horizontalCenter</span>: <span style="font-style: italic; ">parent</span>.horizontalCenter; <span style="color: #800000; ">bottomMargin</span>: 20 }</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> <span style="color: #800000; ">text</span>: <span style="color: #008000; ">"Click</span> <span style="color: #008000; ">anywhere</span> <span style="color: #008000; ">to</span> <span style="color: #008000; ">clear</span> <span style="color: #008000; ">the</span> <span style="color: #008000; ">chart"</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "> }</pre> <pre style="margin-top: 0px; margin-bottom: 0px; ">}</pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><span style="color: #008000; ">//![0]</span></pre> <pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><br /></pre></div><img src ="http://www.cppblog.com/lauer3912/aggbug/192893.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-10-06 08:10 <a href="http://www.cppblog.com/lauer3912/archive/2012/10/06/192893.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt Quick (Qt User Interface Creation Kit)</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/16/153598.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 16 Aug 2011 15:15:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/16/153598.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/153598.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/16/153598.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/153598.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/153598.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #363534; font-family: Verdana, 'DejaVu Sans', Geneva, sans-serif; font-size: 12px; line-height: 18px; background-color: #ffffff; "><h1 style="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: 24px; font-weight: bold; line-height: 1.15; font-family: Arial, FreeSans, sans-serif; color: #363534; ">Qt Quick (Qt User Interface Creation Kit)</h1></span><a href="https://developer.qt.nokia.com/wiki/QML">https://developer.qt.nokia.com/wiki/QML<br /><br /><br /><span style="color: #363534; font-family: Verdana, 'DejaVu Sans', Geneva, sans-serif; line-height: 18px; "><h1>Qt Quick (Qt User Interface Creation Kit)</h1><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px; ">The key new feature of the&nbsp;<a href="http://doc.qt.nokia.com/4.7" 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: #44a51c; text-decoration: none; ">Qt 4.7</a>&nbsp;<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; font-style: italic; ">[doc.qt.nokia.com]</em>&nbsp;and&nbsp;<a href="http://developer.qt.nokia.com/wiki/Category:Tools::QtCreator" 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: #44a51c; text-decoration: none; ">Qt Creator</a>&nbsp;<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; font-style: italic; ">[developer.qt.nokia.com]</em>&nbsp;2.1 releases is&nbsp;<a href="http://doc.qt.nokia.com/4.7/qtquick.html" 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: #44a51c; text-decoration: none; ">Qt Quick</a>&nbsp;<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; font-style: italic; ">[doc.qt.nokia.com]</em>: a high-level UI technology that allows developers and UI designers to work together to create animated, touch-enabled UIs and lightweight applications. It includes:</p><ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 45px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">New Tools in the Qt Creator&nbsp;<span 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: #363534; ">IDE</span>: including a visual editor that allows UI designers and developers to cooperate, working on the same code in an iterative approach</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><span 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: #363534; ">QML</span>&nbsp;(Qt Meta-Object Language): an easy to use, declarative language</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">QtDeclarative: a new module in the Qt library that enables a new declarative programming approach</li></ol><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px; ">And while no C++ programming skills are needed to use Qt Quick, it is 100% based on Qt and can be extended from C++ (and other languages, thanks to&nbsp;<a href="https://developer.qt.nokia.com/wiki/Category:LanguageBindings" 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: #44a51c; text-decoration: none; ">the bindings</a>), limited only by your creativity.</p><a name="60efea20524f0578630c5954422a1ce4" 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: rgb(68, 165, 28); text-decoration: none; "></a><h2>Scope (Qt Creator 2.1 and Quick)</h2><ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 15px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><span 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; ">QML</span>&nbsp;project wizard and project management (new file format for pure&nbsp;<span 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; ">QML</span>&nbsp;applications)</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; ">Advanced&nbsp;<span 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; ">QML</span>&nbsp;editor with syntax highlighting, code completion, integrated help features and more</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; ">Qt Quick Designer: Visual&nbsp;<span 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; ">WYSIWYG</span>&nbsp;editor to create Qt Quick user interfaces (technical preview)</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; ">Qt Quick Components: Common UI Elements that fit into platform Look &amp; Feel</li></ul><a name="b1daa18259a4fca1766e0285ce843d08" 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: rgb(68, 165, 28); text-decoration: none; "></a><h2><span 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; ">QML</span>&nbsp;vs. Widget-based&nbsp;<span 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; ">GUI</span></h2><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px; ">Qt beginners often ask: What option will be the best for creating my user interface. With Qt there are 3 techniques (wich can be integrated):</p><ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 15px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; ">using Qt Designer to create *.ui files, a&nbsp;<span 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; ">XML</span>-based UI description</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; ">coding the setup of your UI in C++ with Qt widgets classes</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; ">write or visually design (or modeling with Qt Creator 2.1)&nbsp;<span 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; ">QML</span>&nbsp;files</li></ul><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px; "></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px; "><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; font-style: italic; ">The HowTo is still to be done</em>&nbsp;but use the&nbsp;<a href="https://developer.qt.nokia.com/wiki/Tagging" 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: #44a51c; text-decoration: none; ">tag</a>&nbsp;<a href="http://developer.qt.nokia.com/search/tag/qml+vs+widget" 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: #44a51c; text-decoration: none; ">qml vs widget</a>&nbsp;<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; font-style: italic; ">[developer.qt.nokia.com]</em>&nbsp;when searching and finding, thx&nbsp;<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 2px; padding-bottom: 2px; padding-left: 0px; font-family: 'Courier New', Courier, monospace; border-top-left-radius: 4px 4px; border-top-right-radius: 4px 4px; border-bottom-right-radius: 4px 4px; border-bottom-left-radius: 4px 4px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #f0f0f0; border-right-color: #f0f0f0; border-bottom-color: #f0f0f0; border-left-color: #f0f0f0; background-image: -webkit-gradient(linear, 100% 100%, 0% 0%, from(#ffcc0e), to(#ffffff)); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">:)</span></p><a name="bd908db5ccb07777ced8023dffc802f4" 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: rgb(68, 165, 28); text-decoration: none; "></a><h2>Links</h2><ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 15px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><a href="http://doc.qt.nokia.com/4.7-snapshot/qtquick.html" 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: #44a51c; text-decoration: none; ">Getting Started</a>&nbsp;<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; font-style: italic; ">[doc.qt.nokia.com]</em></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><a href="http://doc.qt.nokia.com/qtcreator-2.1-snapshot/creator-qml-application.html" 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: #44a51c; text-decoration: none; ">Creating a Qt Quick Application</a>&nbsp;<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; font-style: italic; ">[doc.qt.nokia.com]</em></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><a href="http://doc.qt.nokia.com/qtcreator-2.1-snapshot/quick-components.html" 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: #44a51c; text-decoration: none; ">Creating&nbsp;<span 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; ">QML</span>&nbsp;Components</a>&nbsp;<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; font-style: italic; ">[doc.qt.nokia.com]</em></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><a href="http://developer.qt.nokia.com/wiki/QtQuickOpenComponents" 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: #44a51c; text-decoration: none; ">Open Qt Quick Components</a>&nbsp;<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; font-style: italic; ">[developer.qt.nokia.com]</em></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><a href="http://developer.qt.nokia.com/wiki/QtQuickMinutes" 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: #44a51c; text-decoration: none; ">Qt Quick sync meeting minutes</a>&nbsp;<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; font-style: italic; ">[developer.qt.nokia.com]</em></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><a href="https://developer.qt.nokia.com/wiki/labs.qt.nokia.com/2010/10/19/exporting-qml-from-photoshop-and-gimp/" 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: #44a51c; text-decoration: none; ">Exporting&nbsp;<span 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; ">QML</span>&nbsp;from photoshop and&nbsp;<span 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; ">GIMP</span></a>&nbsp;&#8211;&nbsp;<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; font-style: inherit; font-weight: bold; "><span 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; ">WIP</span></strong></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><a href="https://projects.forum.nokia.com/qmluiexamples" 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: #44a51c; text-decoration: none; "><span 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; ">QML</span>&nbsp;UI examples on Forum Nokia</a>&nbsp;<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; font-style: italic; ">[projects.forum.nokia.com]</em></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><a href="http://developer.qt.nokia.com/wiki/Qt_Quick_Tutorial" title="not yet complete" 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: #44a51c; text-decoration: none; ">Qt Quick Tutorial</a>&nbsp;<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; font-style: italic; ">[developer.qt.nokia.com]</em></li></ul><h3>Categories:</h3><ul id="nav_categories" style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 15px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><a href="https://developer.qt.nokia.com/wiki/Category:Developing_with_Qt" 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: #44a51c; text-decoration: none; ">Developing with Qt</a><ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(https://developer.qt.nokia.com/images/qtdn/cdk/bullet_square.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 6px; background-repeat: no-repeat no-repeat; "><a href="https://developer.qt.nokia.com/wiki/Category:Developing_with_Qt::Qt_Quick" 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: #44a51c; text-decoration: none; ">Qt Quick</a></li></ul></li></ul></span></a><img src ="http://www.cppblog.com/lauer3912/aggbug/153598.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-16 23:15 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/16/153598.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用QML实现浮动桌面搜索框</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/05/152500.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 23:33:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/05/152500.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152500.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/05/152500.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152500.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152500.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 使用QML实现浮动桌面搜索框前段时间接触了一下QML，深深地被这门强大易用的语言所吸引。QML的语法类似CSS，可以引入javascript作为逻辑，还能够和C++对象交互。QML带来的好处至少有以下几点：&nbsp;分工更明确：设计师可以专攻QML制作UI，C++工程师也能专注于自己的本职工作。开发更高效：重新编写的QML不需要编译（因为它是一门脚本语言），所以只需要刷新一下你的QML View...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2011/08/05/152500.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/152500.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-05 07:33 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/05/152500.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt文章精选（标题及链接）</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/05/152499.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 23:28:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/05/152499.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152499.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/05/152499.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152499.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152499.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><h3 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; ">原创:</h3><h4 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; "><li><h4 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://blog.csdn.net/changsheng230/archive/2010/12/19/6085080.aspx" style="color: #336699; text-decoration: none; ">浅议Qt的事件处理机制 一</a></h4></li></h4><li><h4 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://blog.csdn.net/changsheng230/archive/2010/12/22/6092978.aspx" style="color: #336699; text-decoration: none; ">浅议Qt的事件处理机制 二</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2010/11/30/6044599.aspx" style="color: #336699; text-decoration: none; ">Qt的内省机制剖析</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2011/01/04/6114819.aspx" style="color: #336699; text-decoration: none; ">梦工厂动画与Qt</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2011/01/27/6167059.aspx" style="color: #336699; text-decoration: none; ">QML与C++混合编程使用</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2011/01/29/6168795.aspx" style="color: #336699; text-decoration: none; ">Qt/Qt Quick宏浅议</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2011/01/29/6169155.aspx" style="color: #336699; text-decoration: none; ">Q_INVOKABLE与invokeMethod用法全解</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2010/12/10/6068496.aspx" style="color: #336699; text-decoration: none; ">Qt 在symbian^3, windows 7 phone的用户体验</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2010/12/23/6095288.aspx" style="color: #336699; text-decoration: none; ">Qt资源链接收藏</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2011/01/25/6163044.aspx" style="color: #336699; text-decoration: none; ">Qt 好书好文推荐</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2010/07/24/5761590.aspx" style="color: #336699; text-decoration: none; ">诺基亚手机开发相关论坛网站推荐</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/article/details/%E5%88%9B%E5%BB%BAqt%20quick%20(qml)%20%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F" style="color: #336699; text-decoration: none; ">创建Qt quick (qml) 应用程序</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2010/12/31/6110303.aspx" style="color: #336699; text-decoration: none; ">Thread affinity与跨线程信号槽</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2010/12/29/6105018.aspx" style="color: #336699; text-decoration: none; ">Qt的智能指针使用指南</a></h4></li><li><h4 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; "><span class="link_title"><a title="Qt的字符集编码以及转换" href="http://blog.csdn.net/changsheng230/article/details/6588447" style="color: #336699; text-decoration: none; ">Qt的字符集编码以及转换</a></span><span class="link_title"></span></h4></li><li><h4 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; "><span class="link_title"><a title="QImage, QPixmap 的官方解释摘录" href="http://blog.csdn.net/changsheng230/article/details/6452825" style="color: #336699; text-decoration: none; ">QImage, QPixmap 的官方解释摘录</a></span><span class="link_title"></span></h4></li><li><h4 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; "><span class="link_title"><a title="Qt  认证考试有用链接" href="http://blog.csdn.net/changsheng230/article/details/6451995" style="color: #336699; text-decoration: none; ">Qt 认证考试有用链接</a></span></h4></li><h4 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;</h4><li><h3 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; ">译文：</h3></li><li><h4 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://blog.csdn.net/changsheng230/archive/2010/12/27/6101232.aspx" style="color: #336699; text-decoration: none; ">事件循环与线程 一</a>&nbsp;&nbsp; （Event,Thread and QObject）</h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2011/01/19/6153449.aspx" style="color: #336699; text-decoration: none; ">事件循环与线程 二</a>&nbsp;&nbsp; （推荐）</h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2011/01/30/6170007.aspx" style="color: #336699; text-decoration: none; ">QML与现有Qt UI代码的整合</a></h4></li><h3 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; "></h3><h3 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;</h3><h3 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; ">转帖：</h3><li><h4 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; "></h4><h4 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://blog.csdn.net/changsheng230/archive/2010/11/30/6044456.aspx" style="color: #336699; text-decoration: none; ">Qt源码分析之信号和槽机制</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2010/12/01/6046846.aspx" style="color: #336699; text-decoration: none; ">Qt源码分析之QObject</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2010/12/23/6095232.aspx" style="color: #336699; text-decoration: none; ">Qt事件和事件过滤器</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2011/01/28/6167933.aspx" style="color: #336699; text-decoration: none; ">Qt版权介绍：GPL, LGPL 以及 Commercial 授权</a></h4></li><li><h4 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://blog.csdn.net/changsheng230/archive/2011/02/03/6172171.aspx" style="color: #336699; text-decoration: none; ">KDE/QT 与 GNOME/GTK 之争</a></h4>&nbsp;&nbsp;<h4 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://blog.csdn.net/changsheng230/archive/2011/01/19/6153449.aspx" style="color: #336699; text-decoration: none; "></a></h4><h4 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; "><hr /></h4><h4 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; "><p><span style="font-size: 16px; ">请尊重原创作品和译文。转载请保持文章完整性，并以超链接形式注明原始作者</span><a href="http://blog.csdn.net/changsheng230" style="color: #336699; text-decoration: none; "><span style="font-size: 16px; ">主站点</span></a><span style="font-size: 16px; ">地址，方便其他朋友提问和指正。</span></p></h4></li></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152499.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-05 07:28 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/05/152499.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt资源链接收藏</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/05/152497.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 23:22:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/05/152497.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152497.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/05/152497.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152497.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152497.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><h4 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>Qt在线文档</strong></h4><p><span style="text-decoration: underline; "><span style="color: #810081; "><a href="http://doc.qt.nokia.com/4.7/" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/</a></span></span></p><p>&nbsp;</p><h4 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>Qt e-Learning</strong></h4><p><a href="http://qt.nokia.com/developer/learning/elearning" style="color: #336699; text-decoration: none; ">http://qt.nokia.com/developer/learning/elearning</a></p><p><a href="http://wikis.in.nokia.com/QtSoftware/LearnQt" style="color: #336699; text-decoration: none; ">http://wikis.in.nokia.com/QtSoftware/LearnQt</a></p><p><a href="http://www.ics.com/learning/icsnetwork/" style="color: #336699; text-decoration: none; ">http://www.ics.com/learning/icsnetwork/</a></p><p>&nbsp;</p><h4 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>官方Qt移动开发社区、资源、Wiki</strong></h4><p><a href="http://help.github.com/" style="color: #336699; text-decoration: none; ">Getting started with Git and GitHub</a></p><p><a href="https://projects.forum.nokia.com/home/" style="color: #336699; text-decoration: none; ">Nokia Forum projects</a></p><p><a href="http://forum.nokia.com/" style="color: #336699; text-decoration: none; ">http://forum.nokia.com</a></p><p><a href="http://forum.nokia.com.cn/" style="color: #336699; text-decoration: none; ">http://forum.nokia.com.cn/</a>&nbsp;</p><p><a href="http://wiki.forum.nokia.com/index.php/Qt_%E5%BC%80%E5%8F%91" style="color: #336699; text-decoration: none; ">http://wiki.forum.nokia.com/index.php/Qt_%E5%BC%80%E5%8F%91</a></p><p>&nbsp;</p><h4 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; ">官方Qt论坛</h4><p><a href="http://developer.qt.nokia.com/forums" style="color: #336699; text-decoration: none; ">http://developer.qt.nokia.com/forums</a></p><h4 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; "></h4><h4 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; ">Qt for Symbian 开发资源</h4><p><a href="http://discussion.forum.nokia.com/forum/showthread.php?162323-Qt-for-Symbian-development-resources" style="color: #336699; text-decoration: none; ">http://discussion.forum.nokia.com/forum/showthread.php?162323-Qt-for-Symbian-development-resources</a></p><p>&nbsp;</p><h4 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; ">中文Qt网站</h4><p><a class="external-link offSite" href="http://qt.csdn.net/" target="_blank" style="color: #336699; text-decoration: none; "><span style="color: #44a51c; ">http://qt.csdn.net</span></a></p><p><a class="external-link offSite" href="http://discussion.forum.nokia.com/forum/forumdisplay.php?f=204" target="_blank" style="color: #336699; text-decoration: none; "><span style="color: #44a51c; ">诺基亚论坛上的Qt for Symbian中文论坛</span></a></p><p><span class="718475902-02122008"><span class="link-external"><a class="external-link offSite" href="http://www.qtcn.org/" target="_blank" style="color: #336699; text-decoration: none; "><span style="color: #44a51c; ">http://www.qtcn.org</span></a></span></span></p><p><span class="718475902-02122008"><span class="link-external"><a class="external-link offSite" href="http://www.qteverywhere.com/" target="_blank" style="color: #336699; text-decoration: none; "><span style="color: #44a51c; ">www.qteverywhere.com</span></a></span></span></p><p>&nbsp;</p><p>&nbsp;</p><h4 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; ">中文文档</h4><p><span style="text-decoration: underline; "><span style="color: #810081; "><a href="http://forum.nokia.com.cn/document_1.html" style="color: #336699; text-decoration: none; ">http://forum.nokia.com.cn/document_1.html</a></span></span></p><p><a href="http://qtdocs.sourceforge.net/index.php/%E5%88%86%E7%B1%BB:Qt_%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C" style="color: #336699; text-decoration: none; ">http://qtdocs.sourceforge.net/index.php/%E5%88%86%E7%B1%BB:Qt_%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C</a></p><p><strong><span><br /></span></strong></p><h4 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; "><span style="color: #810081; "><span style="font-family: mceinline; ">其他</span></span></h4><p>&nbsp;</p><p>如果在开发中遇到了技术细节上的问题，相信再下面两个论坛搜索相关关键字会比直接在baidu/google上搜强很多</p><p><a href="http://lists.trolltech.com/qt-interest/" style="color: #336699; text-decoration: none; ">http://lists.trolltech.com/qt-interest/</a></p><p>&nbsp;</p><p>&nbsp;</p><p>Qt在SlideShare的幻灯片</p><p><span style="text-decoration: underline; "><span style="color: #810081; "><a href="http://www.slideshare.net/tag/qt" style="color: #336699; text-decoration: none; ">http://www.slideshare.net/tag/qt</a></span></span></p><p>&nbsp;</p><p><span style="text-decoration: underline; "><span style="color: #810081; "></span></span></p><h4 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; ">非官方的优秀Qt论坛</h4><p><a href="http://www.qtcentre.org/forum/" style="color: #336699; text-decoration: none; ">http://www.qtcentre.org/forum/</a></p><p>&nbsp;</p><p>&nbsp;</p></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152497.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-05 07:22 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/05/152497.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt版权介绍：GPL, LGPL 以及 Commercial 授权</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/05/152495.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 23:18:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/05/152495.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152495.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/05/152495.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152495.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152495.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><div class="tit">Qt GPL, LGPL &amp; Commercial License</div><div class="tit"></div><table border="0"><tbody><tr><td><div id="blog_text" class="cnt"><p>From:</p><p>http://www.qteverywhere.com/</p><p>&nbsp;</p><p>Qt 4.5中提供了三种授权协议，分别是GPL, LGPL和Commercial，可能很多人要问，为什么同样的一个产品要提供三种授权协议，什么情况下使用什么的样的授权协议最合适？在这里我就大致解释一下：</p><p>&nbsp;</p><p>GPL全称是The GNU General Public License，是目前大多数的GNU程序和超过半数的自由软件使用的许可协议。GPL的出发点是代码的开源/免费使用和引用/修改/衍生代码的开源/免 费使用，但不允许修改后和衍生的代码做为闭源的商业软件发布和销售。<br />GPL协议的主要内容是只要在一个软件中使用(&#8221;使用&#8221;指类库引用，修改后的代码或者衍生代码)GPL 协议的产品，则该软件产品必须也采用GPL协议，既必须也是开源和免费。这就是所谓的&#8221;传染性&#8221;。GPL协议的产品作为一个单独的产品使用没有任何问题， 还可以享受免费的优势。</p><p>&nbsp;</p><p>回到LGPL，LGPL的全称是 GNU Lesser General Public License，GNU 较宽松公共许可证，也是由协议是由自由软体基金会发布的许可证，是一个主要为类库使用设计的开源协议，和GPL要求任何使用/修改/衍生之GPL类库的的 软件必须采用GPL协议不同。LGPL允许商业软件通过类库引用(link)方式使用LGPL类库而不需要开源商业软件的代码。这使得采用LGPL协议的 开源代码可以被商业软件作为类库引用并发布和销售。</p><p>&nbsp;</p><p>除了GPL和LGPL两种开源协议之外，Qt还提供了Commercial商业协议，Qt的商业协议是由Nokia定义的，由Nokia和购买方签 订的，具有法律效应的Qt产品授权协议。 Commercial License相教与GPL和LGPL，对于商业客户提供了更多的灵活性，客户可以任意的修改Qt的源代码，开发商业软件，而不需要公开任何源代码。并 且，在Commercial License中，我们还提供了技术支持服务。当然，商业授权协议是需要费用的。</p><p>到底什么时候需要选择GPL和LGPL呢？一个最显而易见的理由就是他们都是免费的，使用LGPL和GPL版本的Qt是不需要支付任何费用的，当然 我们也相应的不会提供技术支持。如果你打算开发真正的开源软件，并希望使用者也可以保持开源，那么GPL是更好的选择，因为所有人，不论你自己还是将来基 于你的代码进行再次开发都必须开源。如果你打算开发闭源（不开放源代码）的商业软件，那么LGPL则更适合，但必须满足下面两个条件：<br />1. 你的应用程序应该动态链接Qt函数库，并使你的应用程序与未做修改的LGPL库分开发布。同时必须确保使用者（接受者）知道应用程序使用了LGPL版本的Qt；<br />2. 如果你对LGPL版本的Qt进行了任何修改，并发布，则必须遵循LGPL 条款发布。任何使用者有权利得到这些修改（通常情况下是源代码），并且确保使用者可以通过这些修改自己生成相应你修改过的Qt版本。</p><p>相信到这里大家已经对Qt提供的这三种协议有了基本的了解，通常大家还会有一个疑问，就是基于这三种授权协议的Qt产品到底由多少功能上的区别，是 不是商业版本的会更完整，性能更好一些？这里我可以负责任的说：99%的代码都是一样的，无论是GPL, LGPL还是Commercial，功能，性能都没有区别，唯一的区别就在于授权协议的不同。</p><p>还有一点需要说明的就是，由于LGPL是在Qt4.5这个版本里面才引入的，所以之前的Qt版本，4.4或者3.x的版本，并不提供LGPL协议，是不可逆的。同时未来发布的Qt版本，就一直会提供三种不同的授权协议版本。</p><p>&nbsp;</p><p>下面有一些链接，有兴趣想深入了解这些授权协议的同学，可以学习学习</p><p>GPL协议原文 －&nbsp;<a href="http://www.gnu.org/copyleft/gpl.html" target="_blank" style="color: #336699; text-decoration: none; ">http://www.gnu.org/copyleft/gpl.html</a><br />GPL协议中文译文 －&nbsp;<a href="http://bergwolf.googlepages.com/gplv3_zh" target="_blank" style="color: #336699; text-decoration: none; ">http://bergwolf.googlepages.com/gplv3_zh</a><br />LGPL协议原文 -&nbsp;<a href="http://www.gnu.org/copyleft/lesser.html" target="_blank" style="color: #336699; text-decoration: none; ">http://www.gnu.org/copyleft/lesser.html</a><br />LGPL协议中文译文 －&nbsp;<a href="http://www.thebigfly.com/gnu/lgpl/lgpl-v3.php" target="_blank" style="color: #336699; text-decoration: none; ">http://www.thebigfly.com/gnu/lgpl/lgpl-v3.php</a><br />58种不同的开源协议 －&nbsp;<a href="http://www.fsf.org/licensing/licenses/" target="_blank" style="color: #336699; text-decoration: none; ">http://www.fsf.org/licensing/licenses/</a><br />什么是动态链接 －&nbsp;<a href="http://zh.wikipedia.org/wiki/%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93" target="_blank" style="color: #336699; text-decoration: none; ">http://zh.wikipedia.org/wiki/%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93</a><br />官方声明 －&nbsp;<a href="http://www.qtsoftware.com/about/news/lgpl-license-option-added-to-qt" target="_blank" style="color: #336699; text-decoration: none; ">http://www.qtsoftware.com/about/news/lgpl-license-option-added-to-qt</a><br />官方Q&amp;A －&nbsp;<a href="http://www.qtsoftware.com/about/licensing/frequently-asked-questions" target="_blank" style="color: #336699; text-decoration: none; ">http://www.qtsoftware.com/about/licensing/frequently-asked-questions</a></p></div></td></tr></tbody></table></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152495.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-05 07:18 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/05/152495.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt/Qt Quick宏浅议</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/05/152494.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 23:16:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/05/152494.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152494.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/05/152494.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152494.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152494.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><p><span style="font-size: medium; ">请尊重原创作品和译文。转载请保持文章完整性，并以超链接形式注明原始作者</span><span style="font-size: medium; ">地址<a href="http://blog.csdn.net/changsheng230" style="color: #336699; text-decoration: none; ">http://blog.csdn.net/changsheng230</a>，方便其他朋友提问和指正。</span></p><p>&nbsp;</p><p>刚开始接触Qt的朋友可能对Qt在使用当中需要声明的各色各样的宏感到神秘而又陌生，本文将介绍Qt中经常使用的几个宏： Q_OBJECT, SIGNAL与SLOT, Q_SIGNALS 与 Q_SLOTS, Q_EMIT ,Q_INVOKABLE, Q_PROPERTY：</p><p>&nbsp;</p><p>宏的头文件出处： $QTDIR/src/corelib/kernel/qobjectdefs.h</p><h4 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>Q_OBJECT</strong></h4><p>#define Q_OBJECT /&nbsp;<br />public: /&nbsp;<br />&nbsp;&nbsp;&nbsp; Q_OBJECT_CHECK /&nbsp;<br />&nbsp;&nbsp;&nbsp; static const QMetaObject staticMetaObject; /&nbsp;<br />&nbsp;&nbsp;&nbsp; Q_OBJECT_GETSTATICMETAOBJECT /&nbsp;<br />&nbsp;&nbsp;&nbsp; virtual const QMetaObject *metaObject() const; /&nbsp;<br />&nbsp;&nbsp;&nbsp; virtual void *qt_metacast(const char *); /&nbsp;<br />&nbsp;&nbsp;&nbsp; QT_TR_FUNCTIONS /&nbsp;<br />&nbsp;&nbsp;&nbsp; virtual int qt_metacall(QMetaObject::Call, int, void **); /</p><p>宏Q_OBJECT是Qt所有宏中最为重要的一个，Q_OBJECT是使用信号槽机制以及其他所有元对象系统提供的服务（内省、invokeMethod，元对象property系统等等）的前提条件。有关Q_OBJECT的讨论请参考<a href="http://blog.csdn.net/changsheng230/archive/2010/12/01/6046846.aspx" style="color: #336699; text-decoration: none; ">Qt源码分析之QObject</a>。&nbsp;</p><h4 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>SIGNAL与SLOT</strong></h4><p>这两个宏是调用connect方法时用到:</p><p>&nbsp;</p><div class="dp-highlighter bg_cpp" style="width: 687px; "><div class="bar"><div class="tools"><a href="http://blog.csdn.net/changsheng230/article/details/6168795#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></div></div><ol start="1" class="dp-cpp" style="border-width: initial; border-color: initial; "><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; ">QObject::connect(myButton,&nbsp;SIGNAL(clicked()),&nbsp;&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label,&nbsp;&nbsp;SLOT(showText()));&nbsp;&nbsp;</span></li></ol></div>&nbsp;<p>&nbsp;</p><p>那么宏SIGNAL和SLOT为我们做了那些事情呢，看一下源代码：</p><p>&nbsp;</p><div class="dp-highlighter bg_cpp" style="width: 687px; "><div class="bar"><div class="tools"><a href="http://blog.csdn.net/changsheng230/article/details/6168795#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></div></div><ol start="1" class="dp-cpp" style="border-width: initial; border-color: initial; "><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; ">$QTDIR/src/corelib/kernel/qobjectdefs.h&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="preprocessor" style="border-width: initial; border-color: initial; ">#&nbsp;define&nbsp;SLOT(a)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qFlagLocation("1"#a&nbsp;QLOCATION)&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="preprocessor" style="border-width: initial; border-color: initial; ">#&nbsp;define&nbsp;SIGNAL(a)&nbsp;&nbsp;&nbsp;qFlagLocation("2"#a&nbsp;QLOCATION)</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">$QTDIR/src/corelib/kernel/qobject.cpp&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="keyword" style="border-width: initial; border-color: initial; ">const</span><span style="border-width: initial; border-color: initial; ">&nbsp;</span><span class="datatypes" style="border-width: initial; border-color: initial; color: #2e8b57; font-weight: bold; ">char</span><span style="border-width: initial; border-color: initial; ">&nbsp;*qFlagLocation(</span><span class="keyword" style="border-width: initial; border-color: initial; ">const</span><span style="border-width: initial; border-color: initial; ">&nbsp;</span><span class="datatypes" style="border-width: initial; border-color: initial; color: #2e8b57; font-weight: bold; ">char</span><span style="border-width: initial; border-color: initial; ">&nbsp;*method)&nbsp;&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">{&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">static</span><span style="border-width: initial; border-color: initial; ">&nbsp;</span><span class="datatypes" style="border-width: initial; border-color: initial; color: #2e8b57; font-weight: bold; ">int</span><span style="border-width: initial; border-color: initial; ">&nbsp;idx&nbsp;=&nbsp;0;&nbsp;&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;flagged_locations[idx]&nbsp;=&nbsp;method;&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;idx&nbsp;=&nbsp;(idx+1)&nbsp;%&nbsp;flagged_locations_count;&nbsp;&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">return</span><span style="border-width: initial; border-color: initial; ">&nbsp;method;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">}&nbsp;&nbsp;</span></li></ol></div>&nbsp;<p>&nbsp;</p><p>原来它会基于把我们定义的信号、槽的名称返回一个字符串，比如SIGNAL(clicked()) 返回字符串 &#8220;2clicked()&#8221;, SLOT(showText())返回字符串&#8220;1showText()&#8221;</p><p><strong></strong></p><div class="dp-highlighter bg_cpp" style="width: 687px; "><div class="bar"><div class="tools"><strong><a href="http://blog.csdn.net/changsheng230/article/details/6168795#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></strong></div></div><ol start="1" class="dp-cpp" style="border-width: initial; border-color: initial; "><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><strong><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; ">Q_SIGNALS&nbsp;与&nbsp;Q_SLOTS&nbsp;&nbsp;</span></span></strong></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><strong><span style="border-width: initial; border-color: initial; "><span class="preprocessor" style="border-width: initial; border-color: initial; ">#&nbsp;&nbsp;define&nbsp;slots&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></strong></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><strong><span style="border-width: initial; border-color: initial; "><span class="preprocessor" style="border-width: initial; border-color: initial; ">#&nbsp;&nbsp;define&nbsp;signals&nbsp;protected&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></strong></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><strong><span style="border-width: initial; border-color: initial; "><span class="preprocessor" style="border-width: initial; border-color: initial; ">#&nbsp;define&nbsp;Q_SLOTS&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></strong></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><strong><span style="border-width: initial; border-color: initial; "><span class="preprocessor" style="border-width: initial; border-color: initial; ">#&nbsp;define&nbsp;Q_SIGNALS&nbsp;protected</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></strong></li></ol></div><strong>&nbsp;</strong><p>&nbsp;</p><p>Q_SIGNALS 与 Q_SLOTS是Qt 4.1引入的，它们用来替换关键字signals和slots，原因是更好的与第三方信号槽机制兼容，比如boost库。尽管Q_SIGNALS 与 Q_SLOTS看起来没有做什么。其实不然，QT的元对象编译器moc会识别声明在头文件中的宏Q_SIGNALS，Q_SLOTS。并做为依据，生成元对象模型数据，详见文中最后所示代码实例</p><h4 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>Q_EMIT</strong></h4><pre style="word-wrap: break-word; white-space: normal; "><span style="font-family: monospace; font-size: x-small; "><span>#define Q_EMIT #define emit</span></span></pre><p><span style="white-space: normal; ">Q_EMIT用来替换关键字emit,原因也是更好的与第三方信号槽机制兼容，比如boost库。</span></p><p>这里要注意，我们看到Q_EMIT看起来同样的简单， 但它们是有区别的！表面的区别在于Q_SIGNALS 与 Q_SLOTS用在头文件中，而Q_EMIT用在代码视线中。 本质的区别的在于，Q_SIGNALS 与 Q_SLOTS将被moc识别，是必须使用的。而Q_EMIT或者emit是可有可无的。它不会被moc识别，它存在的唯一理由是：<strong>增加代码的可读性。</strong>&nbsp; 也就是说如下代码都能正常工作，但2）的写法也许会惹怒你的同事。</p><p>&nbsp;</p><div class="dp-highlighter bg_cpp" style="width: 687px; "><div class="bar"><div class="tools"><a href="http://blog.csdn.net/changsheng230/article/details/6168795#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></div></div><ol start="1" class="dp-cpp" style="border-width: initial; border-color: initial; "><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="keyword" style="border-width: initial; border-color: initial; ">void</span><span style="border-width: initial; border-color: initial; ">&nbsp;method()&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">{&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1）&nbsp;emit&nbsp;signalA();&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2）&nbsp;signalA();&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">}&nbsp;&nbsp;</span></li></ol></div>&nbsp;<p>&nbsp;</p><h4 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>Q_INVOKABLE</strong></h4><p>#define Q_INVOKABLE</p><p>&nbsp;</p><p>使用Q_INVOKABLE来修饰成员函数，目的在于被修饰的成员函数能够被元对象系统所唤起。这一机制在<strong>Qt C++/QML混合编程，Qt service framework,&nbsp;</strong>以及<strong>Qt/ HTML5混合编</strong><strong>程</strong>里广泛使用。我会随后<strong><a href="http://blog.csdn.net/changsheng230/archive/2011/01/29/6169155.aspx" style="color: #336699; text-decoration: none; ">另撰写一文</a></strong>做深入探讨。</p><p>&nbsp;</p><p>&nbsp;</p><h4 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>Q_PROPERTY</strong></h4><p>&nbsp;</p><p><span>#define Q_PROPERTY(text) &nbsp;&nbsp;</span></p><p>&nbsp;</p><p><span>使用</span>Q_PROPERTY用以声明<strong>属性</strong>，属性类似于成员变量，但它能够被元对象系统所访问。QML的属性便是利用该机制得以实现的。&nbsp;Q_PROPERTY的用法如下：</p><p>&nbsp;</p><pre class=" cpp" name="code" style="word-wrap: break-word; white-space: normal; ">Q_PROPERTY(QString title READ title WRITE setTitle USER true)</pre><p>&nbsp;</p><p><span style="font-family: monospace; font-size: x-small; "><span style="white-space: pre-wrap; "><br /></span></span></p><p>&nbsp;</p><p>接下来，让我们结合代码来看一下上述宏的使用以及元对象编译器是如何利用这些宏的。</p><p>&nbsp;</p><p>&nbsp;</p><div class="dp-highlighter bg_cpp" style="width: 687px; "><div class="bar"><div class="tools"><a href="http://blog.csdn.net/changsheng230/article/details/6168795#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></div></div><ol start="1" class="dp-cpp" style="border-width: initial; border-color: initial; "><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="preprocessor" style="border-width: initial; border-color: initial; ">#include&nbsp;&lt;QDeclarativeItem&nbsp;&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="keyword" style="border-width: initial; border-color: initial; ">class</span><span style="border-width: initial; border-color: initial; ">&nbsp;EllipseItem&nbsp;:&nbsp;</span><span class="keyword" style="border-width: initial; border-color: initial; ">public</span><span style="border-width: initial; border-color: initial; ">&nbsp;QDeclarativeItem&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">{&nbsp;&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;Q_OBJECT&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;Q_PROPERTY(QColor&nbsp;color&nbsp;READ&nbsp;color&nbsp;WRITE&nbsp;setColor&nbsp;NOTIFY&nbsp;colorChanged)&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="keyword" style="border-width: initial; border-color: initial; ">public</span><span style="border-width: initial; border-color: initial; ">:&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;EllipseItem(QDeclarativeItem&nbsp;*parent&nbsp;=&nbsp;0);&nbsp;&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">void</span><span style="border-width: initial; border-color: initial; ">&nbsp;paint(QPainter&nbsp;*painter,&nbsp;</span><span class="keyword" style="border-width: initial; border-color: initial; ">const</span><span style="border-width: initial; border-color: initial; ">&nbsp;QStyleOptionGraphicsItem&nbsp;*option,&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QWidget&nbsp;*widget&nbsp;=&nbsp;0);&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">const</span><span style="border-width: initial; border-color: initial; ">&nbsp;QColor&nbsp;&amp;color()&nbsp;</span><span class="keyword" style="border-width: initial; border-color: initial; ">const</span><span style="border-width: initial; border-color: initial; ">;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">void</span><span style="border-width: initial; border-color: initial; ">&nbsp;setColor(</span><span class="keyword" style="border-width: initial; border-color: initial; ">const</span><span style="border-width: initial; border-color: initial; ">&nbsp;QColor&nbsp;&amp;newColor);&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;Q_INVOKABLE&nbsp;QColor&nbsp;randomColor()&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">const</span><span style="border-width: initial; border-color: initial; ">;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="keyword" style="border-width: initial; border-color: initial; ">public</span><span style="border-width: initial; border-color: initial; ">&nbsp;Q_SLOTS:&nbsp;&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">void</span><span style="border-width: initial; border-color: initial; ">&nbsp;try1();&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">void</span><span style="border-width: initial; border-color: initial; ">&nbsp;try2()&nbsp;{}&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">Q_SIGNALS:&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">void</span><span style="border-width: initial; border-color: initial; ">&nbsp;colorChanged();&nbsp;&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">void</span><span style="border-width: initial; border-color: initial; ">&nbsp;ready();&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="keyword" style="border-width: initial; border-color: initial; ">private</span><span style="border-width: initial; border-color: initial; ">:&nbsp;&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;QColor&nbsp;m_color;&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">};&nbsp;&nbsp;</span></li></ol></div>&nbsp;<p>&nbsp;</p><p>&nbsp;</p><p>以下代码由元对象编译器moc根据上述头文件自动生成：</p><p>&nbsp;</p><p>&nbsp;</p><div class="dp-highlighter bg_cpp" style="width: 687px; "><div class="bar"><div class="tools"><a href="http://blog.csdn.net/changsheng230/article/details/6168795#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></div></div><ol start="1" class="dp-cpp" style="border-width: initial; border-color: initial; "><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="keyword" style="border-width: initial; border-color: initial; ">static</span><span style="border-width: initial; border-color: initial; ">&nbsp;</span><span class="keyword" style="border-width: initial; border-color: initial; ">const</span><span style="border-width: initial; border-color: initial; ">&nbsp;uint&nbsp;qt_meta_data_EllipseItem[]&nbsp;=&nbsp;{&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;content:&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;revision&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;classname&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;<span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;classinfo&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5,&nbsp;&nbsp;&nbsp;14,&nbsp;<span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;methods&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1,&nbsp;&nbsp;&nbsp;39,&nbsp;<span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;properties&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;<span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;enums/sets&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;<span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;constructors&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;flags&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;signalCount</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;signals:&nbsp;signature,&nbsp;parameters,&nbsp;type,&nbsp;tag,&nbsp;flags&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13,&nbsp;&nbsp;&nbsp;12,&nbsp;&nbsp;&nbsp;12,&nbsp;&nbsp;&nbsp;12,&nbsp;0x05,&nbsp;&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;28,&nbsp;&nbsp;&nbsp;12,&nbsp;&nbsp;&nbsp;12,&nbsp;&nbsp;&nbsp;12,&nbsp;0x05,&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;slots:&nbsp;signature,&nbsp;parameters,&nbsp;type,&nbsp;tag,&nbsp;flags&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;36,&nbsp;&nbsp;&nbsp;12,&nbsp;&nbsp;&nbsp;12,&nbsp;&nbsp;&nbsp;12,&nbsp;0x0a,&nbsp;&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;43,&nbsp;&nbsp;&nbsp;12,&nbsp;&nbsp;&nbsp;12,&nbsp;&nbsp;&nbsp;12,&nbsp;0x0a,&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;methods:&nbsp;signature,&nbsp;parameters,&nbsp;type,&nbsp;tag,&nbsp;flags&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;57,&nbsp;&nbsp;&nbsp;12,&nbsp;&nbsp;&nbsp;50,&nbsp;&nbsp;&nbsp;12,&nbsp;0x02,&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;properties:&nbsp;name,&nbsp;type,&nbsp;flags&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;71,&nbsp;&nbsp;&nbsp;50,&nbsp;0x43495103,&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;properties:&nbsp;notify_signal_id&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="border-width: initial; border-color: initial; ">//&nbsp;eod&nbsp;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">};&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span class="keyword" style="border-width: initial; border-color: initial; ">static</span><span style="border-width: initial; border-color: initial; ">&nbsp;</span><span class="keyword" style="border-width: initial; border-color: initial; ">const</span><span style="border-width: initial; border-color: initial; ">&nbsp;</span><span class="datatypes" style="border-width: initial; border-color: initial; color: #2e8b57; font-weight: bold; ">char</span><span style="border-width: initial; border-color: initial; ">&nbsp;qt_meta_stringdata_EllipseItem[]&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="string" style="border-width: initial; border-color: initial; ">"EllipseItem/0/0colorChanged()/0ready()/0"</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="string" style="border-width: initial; border-color: initial; ">"try1()/0try2()/0QColor/0randomColor()/0"</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="string" style="border-width: initial; border-color: initial; ">"color/0"</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">};&nbsp;&nbsp;</span></li></ol></div>&nbsp;<p>&nbsp;</p><p>&nbsp;</p><p>从上面代码实例我们可以看到， QT的元对象编译器moc会识别声明在头文件中的宏Q_SIGNALS，Q_SLOTS, Q_PROPERTY, Q_PROPERTY。并以此做为依据，生成了元对象数据表。在这张元对象数据表中，我们已可以看到，moc根据头文件所声明的宏定义，识别出:</p><ul><li>两个信号：colorChanged(), ready(); &nbsp; &nbsp; &nbsp;(Q_SIGNALS）</li><li>两个槽: &nbsp; &nbsp;try1(), try2() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Q_SLOTS)</li><li>五个方法，其中被标记为<strong>Q_INVOKABLE</strong>的方法randomColor()被记录在元对象字符串数组qt_meta_stringdata_EllipseItem中。 &nbsp;</li><li>一个属性：color &nbsp; (Q_PROPERTY)</li></ul></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152494.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-05 07:16 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/05/152494.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML与现有Qt UI代码的整合</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152476.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 14:38:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152476.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152476.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152476.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152476.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152476.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><p><span>请尊重原创作品和译文。转载请保持文章完整性，并以超链接形式注明原始作者</span><span>地址<a href="http://blog.csdn.net/changsheng230" style="color: #336699; text-decoration: none; ">http://blog.csdn.net/changsheng230</a>，方便其他朋友提问和指正。</span></p><p>将QML整合到基于QWidget UI程序的方法有很多种，而具体采用哪种方法取决于现有UI代码的特性。</p><h4 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; ">与基于QWidget的UI整合</h4><p>如果你已经有了一个基于<a href="http://doc.qt.nokia.com/qwidget.html" style="color: #336699; text-decoration: none; ">QWidget</a>的UI，QML widgets可以使用<a href="http://doc.qt.nokia.com/qdeclarativeview.html" style="color: #336699; text-decoration: none; ">QDeclarativeView</a>来进行集成。<a href="http://doc.qt.nokia.com/qdeclarativeview.html" style="color: #336699; text-decoration: none; ">QDeclarativeView</a>是QWidget的一个子类，所以你可以像加载其他<a href="http://doc.qt.nokia.com/qwidget.html" style="color: #336699; text-decoration: none; ">QWidget</a>一样把它加载进你的UI。 具体方法是使用<a href="http://doc.qt.nokia.com/qdeclarativeview.html#source-prop" style="color: #336699; text-decoration: none; ">QDeclarativeView::setSource</a>()方法加载一个QML文件到视图中，然后将这个视图（即<a href="http://doc.qt.nokia.com/qdeclarativeview.html" style="color: #336699; text-decoration: none; ">QDeclarativeView</a>）加到你的UI中。</p><pre style="word-wrap: break-word; white-space: normal; "><div class="dp-highlighter bg_cpp" style="width: 687px; "><div class="bar"><div class="tools"><a href="http://blog.csdn.net/changsheng230/article/details/6170007#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></div></div><ol start="1" class="dp-cpp" style="border-width: initial; border-color: initial; "><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; ">QDeclarativeView&nbsp;*qmlView&nbsp;=&nbsp;</span><span class="keyword" style="border-width: initial; border-color: initial; ">new</span><span style="border-width: initial; border-color: initial; ">&nbsp;QDeclarativeView;&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">qmlView-&gt;setSource(QUrl::fromLocalFile(<span class="string" style="border-width: initial; border-color: initial; ">"myqml.qml"</span><span style="border-width: initial; border-color: initial; ">));&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">QWidget&nbsp;*widget&nbsp;=&nbsp;myExistingWidget();&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">QVBoxLayout&nbsp;*layout&nbsp;=&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">new</span><span style="border-width: initial; border-color: initial; ">&nbsp;QVBoxLayout(widget);&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">widget-&gt;addWidget(qmlView);&nbsp;&nbsp;</span></li></ol></div></pre><p>这种方法的缺点在于与QWidget相比，QDelarativeVeiw的初始化过程更慢，而且使用更多的内存。如果创建大量的QDelarativeVeiw对象可能会导致性能的下降。在这种情况下，更好的选择是用QML重写你的widgets，使用main QML widget来加载widget, 从而替代QDelarativeVeiw的滥用。</p><p>请注意，QWidgets的UI设计理念与QML并不相同，所以将基于QWidget的应用移植到QML并不总是一个好主意。如果你的UI是由少数几个复杂、静态的元素的组成，使用QWidgets是一个更好的选择。而如果你的UI是由大量简单、动态的元素组成，那么QML则是你的最佳选择。</p><h4 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; ">与基于QGraphicsView的UI整合</h4><h5>将QML widgets加入到QGraphicsScene</h5><p>如果你已经有了一个基于<a href="http://doc.qt.nokia.com/graphicsview.html" style="color: #336699; text-decoration: none; ">Graphics View Framework</a>的UI，你可以直接将QML widgets集成到你的<a href="http://doc.qt.nokia.com/qgraphicsscene.html" style="color: #336699; text-decoration: none; ">QGraphicsScene</a>中。具体方法是使用<a href="http://doc.qt.nokia.com/qdeclarativecomponent.html" style="color: #336699; text-decoration: none; ">QDeclarativeComponent</a>&nbsp;从QML文件中创建一个<a href="http://doc.qt.nokia.com/qgraphicsobject.html" style="color: #336699; text-decoration: none; ">QGraphicsObject</a>，并通过使用<a href="http://doc.qt.nokia.com/qgraphicsscene.html#addItem" style="color: #336699; text-decoration: none; ">QGraphicsScene::addItem</a>(), 方法把这个图形对象加到你的scene中，或者将其父化到已经存在与<a href="http://doc.qt.nokia.com/qgraphicsscene.html" style="color: #336699; text-decoration: none; ">QGraphicsScene</a>的组件中。举例说明:</p><p>&gt;</p><pre style="word-wrap: break-word; white-space: normal; "><div class="dp-highlighter bg_cpp" style="width: 687px; "><div class="bar"><div class="tools"><a href="http://blog.csdn.net/changsheng230/article/details/6170007#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></div></div><ol start="1" class="dp-cpp" style="border-width: initial; border-color: initial; "><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; ">QGraphicsScene*&nbsp;scene&nbsp;=&nbsp;myExistingGraphicsScene();&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">QDeclarativeEngine&nbsp;*engine&nbsp;=&nbsp;<span class="keyword" style="border-width: initial; border-color: initial; ">new</span><span style="border-width: initial; border-color: initial; ">&nbsp;QDeclarativeEngine;&nbsp;&nbsp;</span></span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">QDeclarativeComponent&nbsp;component(engine,&nbsp;QUrl::fromLocalFile(<span class="string" style="border-width: initial; border-color: initial; ">"myqml.qml"</span><span style="border-width: initial; border-color: initial; ">));&nbsp;&nbsp;</span></span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">QGraphicsObject&nbsp;*object&nbsp;=&nbsp;&nbsp;</span></li><li class="alt" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;qobject_cast(component.create());&nbsp;&nbsp;</span></li><li class="" style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">scene-&gt;addItem(object);&nbsp;&nbsp;</span></li></ol></div></pre><p>推荐使用下面的一些<a href="http://doc.qt.nokia.com/qgraphicsview.html" style="color: #336699; text-decoration: none; ">QGraphicsView</a>选项来优化QML UIs的性能：</p><ul><li>QGraphicsView::setOptimizationFlags(<a href="http://doc.qt.nokia.com/qgraphicsview.html#OptimizationFlag-enum" style="color: #336699; text-decoration: none; ">QGraphicsView::DontSavePainterState</a>)</li><li>QGraphicsView::setViewportUpdateMode(<a href="http://doc.qt.nokia.com/qgraphicsview.html#ViewportUpdateMode-enum" style="color: #336699; text-decoration: none; ">QGraphicsView::BoundingRectViewportUpdate</a>)</li><li>QGraphicsScene::setItemIndexMethod(<a href="http://doc.qt.nokia.com/qgraphicsscene.html#ItemIndexMethod-enum" style="color: #336699; text-decoration: none; ">QGraphicsScene::NoIndex</a>)</li></ul><h5>在QML中加载QGraphicsWidget 对象</h5><p>另一个可供选择的方法是将你现有的<a href="http://doc.qt.nokia.com/qgraphicswidget.html" style="color: #336699; text-decoration: none; ">QGraphicsWidget</a>&nbsp;对象暴露给QML，并且在QML中构建你的scene。请参见<a href="http://doc.qt.nokia.com/declarative-cppextensions-qgraphicslayouts.html" style="color: #336699; text-decoration: none; ">图形布局示例</a>，它展示了如何结合<a href="http://doc.qt.nokia.com/qgraphicswidget.html" style="color: #336699; text-decoration: none; ">QGraphicsWidget</a>&nbsp;、<a href="http://doc.qt.nokia.com/qgraphicslinearlayout.html" style="color: #336699; text-decoration: none; ">QGraphicsLinearLayout</a>&nbsp;以及<a href="http://doc.qt.nokia.com/qgraphicsgridlayout.html" style="color: #336699; text-decoration: none; ">QGraphicsGridLayout</a>的使用，将Qt图形布局类暴露给QML。</p><p>为了将现有的<a href="http://doc.qt.nokia.com/qgraphicswidget.html" style="color: #336699; text-decoration: none; ">QGraphicsWidget</a>类暴露给QML，需使用<a href="http://doc.qt.nokia.com/qdeclarativeengine.html#qmlRegisterType" style="color: #220000; text-decoration: none; ">qmlRegisterType</a>()。在QML中使用C++型别的进一步信息，请参见在<a href="http://doc.qt.nokia.com/qml-extending.html" style="color: #336699; text-decoration: none; ">C++中拓展QML</a>。 （译者注：也看参阅<a href="http://blog.csdn.net/changsheng230/archive/2011/01/27/6167059.aspx" style="color: #336699; text-decoration: none; ">QML与C++混合编程使用</a>)</p><p>英文原文出处：<a href="http://doc.qt.nokia.com/4.7/qml-integration.html" style="color: #336699; text-decoration: none; ">integrating QML with existing Qt UI code</a></p></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152476.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 22:38 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152476.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>详解QML与C++混合编程使用</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152474.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 14:31:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152474.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152474.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152474.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152474.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152474.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="font-family: 宋体; font-size: 12px; line-height: normal; background-color: #ffffff; "><p>本文适合于对<strong>Qt Quick</strong>有基本了解的读者。首先回答一个比较常会被问到的问题：什么是<strong>QML</strong>，它与<strong>Quick</strong>的关系是什么？</p><p><strong>Qt Quick</strong>是<strong>Qt&nbsp;</strong>User Interface Creation Kit的缩写，而<strong>QML</strong>是<strong>Qt Quick</strong>最重要的组成部分，<strong>Qt Quick</strong>结合了如下技术：</p><p>组件集合，其中大部分是关于图形界面的</p><p>基于JavaScript陈述性语言：<strong>QML&nbsp;</strong>（Qt Meta-Object Language的缩写）</p><p>用于管理组件并与组件交互的<a href="http://developer.51cto.com/col/1523/" style="text-decoration: none; color: #000000; "><u><font color="#004276">C++&nbsp;</font></u></a>API - QtDeclarative模块</p><p>言归正传：通过Qt Creator，我们可以轻松生成一个Qt Quick的应用工程，从而为QML生成应用程序框架。具体操作详见：创建qt quick (qml) 应用程序。</p><p><strong>C++</strong>与QML的交互是通过注册C++对象给QML环境得以实现的：</p><p>在<a href="http://developer.51cto.com/col/1523/" style="text-decoration: none; color: #000000; "><u><font color="#004276">C++</font></u></a>实现中，非可视化的型别均为QObject的子类，可视化的类型均为QDeclarativeItem的子类。注意：QDeclarativeItem等同于QML的Item类。</p><p>如果用户想要定义自己的型别，做法如下：</p><p>在C++中，实现派生于QObject或QDeclarativeItem的子类，它是新定义item的实体对象；</p><p>在C++中，将1中实现的新item类型注册给QML；</p><p>在QML中，导入含有1中定义的新item的模块；</p><p>在QML中，向使用标准的item一样使用新定义的item</p><p>现举例说明，我们现尝试使用用Qt C++实现的MyButton对象（如下qml代码），它有自己的属性、方法以及信号的handler。用法如下（它与使用其它标准的QML item一样），所需要做的是 需要导入包含MyButton的对应模块名称及其版本&#8220;MyItems 1.0 &#8221;。</p><pre><ol class="dp-xml"><li class="alt"><span><span>//main.qml     </span></span></li><li><span>import Qt 4.7     </span></li><li class="alt"><span>import MyItems 1.0     </span></li><li><span>Item {     </span></li><li class="alt"><span>    width: 300; height: 200     </span></li><li><span>    MyButton {     </span></li><li class="alt"><span>        //注意：x, y, width, height是继承自item的属性，无需再自定义的item中实现     </span></li><li><span>        x: 50; y: 50     </span></li><li class="alt"><span>        width: 200; height: 100     </span></li><li><span>        color: "gray"   //自定义属性     </span></li><li class="alt"><span>        onMySignals:  dosth  //自定义信号mySignals     </span></li><li><span>MouseArea {     </span></li><li class="alt"><span>anchors.fill: parent     </span></li><li><span>onClicked: parent.myColor()   // 调用C++定义的方法myColor     </span></li><li class="alt"><span>}     </span></li><li><span>    }     </span></li><li class="alt"><span>}    </span></li><li><span>//main.qml  </span></li><li class="alt"><span>import Qt 4.7  </span></li><li><span>import MyItems 1.0  </span></li><li class="alt"><span>Item {  </span></li><li><span>    width: 300; height: 200  </span></li><li class="alt"><span>    MyButton {  </span></li><li><span>        //注意：x, y, width, height是继承自item的属性，无需再自定义的item中实现  </span></li><li class="alt"><span>        x: 50; y: 50  </span></li><li><span>        width: 200; height: 100  </span></li><li class="alt"><span>        color: "gray"   //自定义属性  </span></li><li><span>        onMySignals:  dosth  //自定义信号mySignals  </span></li><li class="alt"><span>MouseArea {  </span></li><li><span>anchors.fill: parent  </span></li><li class="alt"><span>onClicked: parent.myColor()   // 调用C++定义的方法myColor  </span></li><li><span>}  </span></li><li class="alt"><span>    }  </span></li><li><span>}  </span></li></ol></pre><p>为了能够上述qml代码工作，需要为在Qt C++代码中注册MyButton及其所属的模块，对应的main.cpp代码如下：</p><pre><ol class="dp-xml"><li class="alt"><span><span>#include </span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">QtGui</span></font></strong><span>/QApplication</span><span class="tag"><strong><font color="#006699">&gt;</font></strong></span><span>     </span></span></li><li><span>#include "qmlapplicationviewer.h"     </span></li><li class="alt"><span>int main(int argc, char *argv[])     </span></li><li><span>{     </span></li><li class="alt"><span>    QApplication app(argc, argv);     </span></li><li><span>    QmlApplicationViewer viewer;     </span></li><li class="alt"><span>    // MyButtonItem是与QML中MyButton相对应的C++实现的类名称     </span></li><li><span>    // 1，0是版本信息；MyItems是MyButton所属的模块名称     </span></li><li class="alt"><span>    qmlRegisterType</span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">MyButtonItem</span><span class="tag">&gt;</span></font></strong><span>("MyItems", 1, 0, "MyButton ");     </span></li><li><span>    viewer.setOrientation(QmlApplicationViewer::Auto);     </span></li><li class="alt"><span>    viewer.setMainQmlFile(QLatin1String("qml/untitled/main.qml"));     </span></li><li><span>    viewer.show();     </span></li><li class="alt"><span>    return app.exec();     </span></li><li><span>}    </span></li><li class="alt"><span>#include </span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">QtGui</span></font></strong><span>/QApplication</span><span class="tag"><strong><font color="#006699">&gt;</font></strong></span><span> </span></li><li><span>#include "qmlapplicationviewer.h"  </span></li><li class="alt"><span>int main(int argc, char *argv[])  </span></li><li><span>{  </span></li><li class="alt"><span>    QApplication app(argc, argv);  </span></li><li><span>    QmlApplicationViewer viewer;  </span></li><li class="alt"><span>    // MyButtonItem是与QML中MyButton相对应的C++实现的类名称  </span></li><li><span>    // 1，0是版本信息；MyItems是MyButton所属的模块名称  </span></li><li class="alt"><span>    qmlRegisterType</span><strong><font color="#006699"><span class="tag">&lt;</span><span class="tag-name">MyButtonItem</span><span class="tag">&gt;</span></font></strong><span>("MyItems", 1, 0, "MyButton ");  </span></li><li><span>    viewer.setOrientation(QmlApplicationViewer::Auto);  </span></li><li class="alt"><span>    viewer.setMainQmlFile(QLatin1String("qml/untitled/main.qml"));  </span></li><li><span>    viewer.show();  </span></li><li class="alt"><span>    return app.exec();  </span></li><li><span>}  </span></li></ol></pre><p>上面我们在QML中MyButton对象，有自己的属性、方法以及信号的handler，其实现均来自Qt C++。Qt C++需要作以下工作：首先要定义 QML中MyButton相对应的C++实现MyButtonItem，它必须继承自QDeclarativeItem</p><p>为了让MyButton对象能够使用其Color属性，MyButtonItem类需要利用QT的PROPERTY系统，为Moc声明其属性</p><p>为了让MyButton对象能够使用其myColor方法，MyButtonItem类需要声明该方法，并标记为Q_INVOKABLE （另外一种解决方案是将myColor声明为槽。</p><p>为了让MyButton对象能够接受到C++所emit的信号，并在onMySignals，MyButtonItem类需要声明mySignals信号</p><pre><ol class="dp-xml"><li class="alt"><span><span>class MyButtonItem : public QDeclarativeItem     </span></span></li><li><span>{     </span></li><li class="alt"><span>    Q_OBJECT     </span></li><li><span>    Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)     </span></li><li class="alt"><span>signals:     </span></li><li><span>    void colorChanged();     </span></li><li class="alt"><span>    void mySignals();     </span></li><li><span>public:     </span></li><li class="alt"><span>    MyButtonItem(QDeclarativeItem *</span><span class="attribute"><font color="#ff0000">parent</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">0</font></span><span>);     </span></li><li><span>    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,     </span></li><li class="alt"><span>               QWidget *</span><span class="attribute"><font color="#ff0000">widget</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">0</font></span><span>);     </span></li><li><span>public:     </span></li><li class="alt"><span>    const QColor &amp;color() const;     </span></li><li><span>    void setColor(const QColor &amp;newColor);     </span></li><li class="alt"><span>    Q_INVOKABLE QColor myColor() const;     </span></li><li><span>// Alternatives for myColor to be called from QML     </span></li><li class="alt"><span>//public slots     </span></li><li><span>    //QColor myColor() const;     </span></li><li class="alt"><span>private:     </span></li><li><span>    QColor m_color;     </span></li><li class="alt"><span>}; </span></li></ol></pre><p>原始作者地址http://blog.csdn.net/changsheng230</p><p>小结：关于详解<strong>QML</strong>与<strong>C++</strong>混合编程使用的内容介绍完了，希望本文对你有所帮助！</p></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152474.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 22:31 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152474.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML 官方教程</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152473.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 14:29:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152473.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152473.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152473.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152473.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152473.html</trackback:ping><description><![CDATA[<div><a href="http://doc.qt.nokia.com/4.7-snapshot/qml-features.html">http://doc.qt.nokia.com/4.7-snapshot/qml-features.html</a></div><img src ="http://www.cppblog.com/lauer3912/aggbug/152473.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 22:29 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152473.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML与c++交互学习笔记(八) qt c++直接调用QML中的函数, 直接设置属性 </title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152472.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 14:05:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152472.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152472.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152472.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152472.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152472.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #984e13; font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #f5f8ee; "><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">1.</font>这里主要是介绍，如何在<font style="line-height: 22px; ">c++</font>中调用<font style="line-height: 22px; ">QML</font>中的函数和设置<font style="line-height: 22px; ">QML</font>中的属性的问题</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">2.</font>具体代码</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="287" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="283" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="283" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">UICtest.qml</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Qt<font color="#c0c0c0" style="line-height: 22px; "> </font>4.7</font>
<font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Rectangle</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">id</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>mainWidget;</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>640</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>480</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">function</font><font color="#c0c0c0" style="line-height: 22px; "> </font>callbyc(v)</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">{</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; ">mainWidget.color<font color="#c0c0c0" style="line-height: 22px; "> </font>=<font color="#c0c0c0" style="line-height: 22px; "> </font>v;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"finish"</font>;</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Rectangle</font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">id</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>secondRect;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">x</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>100;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">y</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>20;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>400;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>300;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Rectangle</font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">x</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>10;</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">y</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>20;</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>30;</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>40;</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">color</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"#FF035721"</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Text</font><font color="#c0c0c0" style="line-height: 22px; ">  </font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">                </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">objectName</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"NeedFindObj"</font>;</font>
<font color="#c0c0c0" style="line-height: 22px; ">                </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">anchors.fill</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>parent;</font>
<font color="#c0c0c0" style="line-height: 22px; ">                </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">text</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">""</font>;</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; ">}</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; ">}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">}</font>
<font style="line-height: 22px; ">}</font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="661" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="657" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="657" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">main.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtGui/QApplication&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeView&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeEngine&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeComponent&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeContext&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeItem&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QMetaObject&gt;</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>main<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">char</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>argv<font color="#000000" style="line-height: 22px; ">[])</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QApplication</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">(</font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argv<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QDeclarativeView</font><font color="#c0c0c0" style="line-height: 22px; "> </font>qmlView<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>setSource<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QUrl</font><font color="#000000" style="line-height: 22px; ">::</font>fromLocalFile<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"../UICtest/UICtest.qml"</font><font color="#000000" style="line-height: 22px; ">));</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>show<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">获取根节点，就是</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">QML</font></font><font color="#008000" style="line-height: 22px; ">中</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">id</font></font><font color="#008000" style="line-height: 22px; ">是<font style="line-height: 22px; ">mainWidget</font></font><font color="#008000" style="line-height: 22px; ">的节点</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QDeclarativeItem</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>item<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font>qobject_cast<font color="#000000" style="line-height: 22px; ">&lt;</font><font color="#800080" style="line-height: 22px; ">QDeclarativeItem</font><font color="#000000" style="line-height: 22px; ">*&gt;(</font>qmlView<font color="#000000" style="line-height: 22px; ">.</font>rootObject<font color="#000000" style="line-height: 22px; ">());</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">item<font color="#000000" style="line-height: 22px; ">-&gt;</font>setProperty<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"color"</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QVariant</font><font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"blue"</font><font color="#000000" style="line-height: 22px; ">));</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">查找到我们需要的节点根均<font style="line-height: 22px; ">objectname</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">NeedFindObj</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">来获得，并设置他的文本属性</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QDeclarativeItem</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>item1<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font>item<font color="#000000" style="line-height: 22px; ">-&gt;</font>findChild<font color="#000000" style="line-height: 22px; ">&lt;</font><font color="#800080" style="line-height: 22px; ">QDeclarativeItem</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*&gt;(</font><font color="#008000" style="line-height: 22px; ">"NeedFindObj"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">if</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">(</font>item1<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; ">item1<font color="#000000" style="line-height: 22px; ">-&gt;</font>setProperty<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"text"</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QVariant</font><font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"OK"</font><font color="#000000" style="line-height: 22px; ">));</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">}</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">调用<font style="line-height: 22px; ">QML</font></font><font color="#008000" style="line-height: 22px; ">中的函数<font style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">分别是</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">函数所在的对象，</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">函数名，返回值，</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">参数</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QVariant</font><font color="#c0c0c0" style="line-height: 22px; "> </font>returnVar<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QVariant</font><font color="#c0c0c0" style="line-height: 22px; "> </font>arg1<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"blue"</font><font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QMetaObject</font><font color="#000000" style="line-height: 22px; ">::</font>invokeMethod<font color="#000000" style="line-height: 22px; ">(</font>item<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"callbyc"</font><font color="#000000" style="line-height: 22px; ">,</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">                              </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_RETURN_ARG</font><font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QVariant</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font>returnVar<font color="#000000" style="line-height: 22px; ">),</font><font color="#800080" style="line-height: 22px; ">Q_ARG</font><font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QVariant</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font>arg1<font color="#000000" style="line-height: 22px; ">));</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qDebug<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">%s"</font><font color="#000000" style="line-height: 22px; ">,</font>returnVar<font color="#000000" style="line-height: 22px; ">.</font>toString<font color="#000000" style="line-height: 22px; ">().</font>toLocal8Bit<font color="#000000" style="line-height: 22px; ">().</font>data<font color="#000000" style="line-height: 22px; ">());</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">.</font>exec<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; ">说明：</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; "></font>这里的根节点是<font style="line-height: 22px; ">id</font>为<font style="line-height: 22px; ">mainWidget</font>的矩形元素，那么在<font style="line-height: 22px; ">C++</font>中获取根节点后就可以，直接的设置他的属性了。其他属性也可以同样<font style="line-height: 22px; ">,</font>调用指定节点内的函数是通过<font style="line-height: 22px; ">QMetaObject</font>中的<font style="line-height: 22px; ">invokeMethod&nbsp;</font>来进行调用的。</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; ">最后所有关于<font style="line-height: 22px; ">QML</font>和<font style="line-height: 22px; ">c++</font>交互部分就基本写完，如果想要更多的东西，或者一些其他方法，强烈看看</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html</font>，或者帮助文档，（究竟是不是我的文档里面没有还是怎么的）</font></p></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152472.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 22:05 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152472.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML与c++交互学习笔记(七)  </title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152471.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 13:59:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152471.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152471.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152471.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152471.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152471.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #984e13; font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #f5f8ee; "><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; ">1.</font>假设这样一种情况</p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "></font>我这里由一个<font style="line-height: 22px; ">Wideget&nbsp;</font>继承自<font style="line-height: 22px; ">QWidget</font>上面添加来一个<font style="line-height: 22px; ">QLabel,&nbsp;</font>一个<font style="line-height: 22px; ">QPushButton</font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "></font>我如何把这个<font style="line-height: 22px; ">Wideget</font>放到<font style="line-height: 22px; ">QML</font>中使用，那么我当<font style="line-height: 22px; ">QPushButton&nbsp;</font>按下后我怎么在<font style="line-height: 22px; ">QML</font>中进行处理呢？</p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "></font>我这里指出一种方法</p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "></font>让<font style="line-height: 22px; ">Wideget&nbsp;</font>继承<font style="line-height: 22px; ">QGraphicsProxyWidget</font>，对<font style="line-height: 22px; ">Wideget</font>进行导出，在<font style="line-height: 22px; ">QML</font>中创建</p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">此对象，在他导出的信中进行处理<font style="line-height: 22px; ">,</font>具体代码。</p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "></font>还有就是这个网址上说明来很多<font style="line-height: 22px; ">QML</font>与<font style="line-height: 22px; ">c++</font>之间通讯的方法，很悲剧的是我的<font style="line-height: 22px; ">assistant</font>中却没有者部分，不知道版本低还是怎么的。</p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><a href="http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html" style="line-height: 22px; text-decoration: none; color: #839432; ">http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html</a></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">2.</font>具体代码</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="396" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="392" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="392" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//widget.h</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#ifndef</font><font color="#c0c0c0" style="line-height: 22px; "> </font>WIDGET_H</font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#define</font><font color="#c0c0c0" style="line-height: 22px; "> </font>WIDGET_H</font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QWidget&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QGraphicsProxyWidget&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QPushButton&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QLabel&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QLineEdit&gt;</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">class</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Widget<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">:</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">public</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QGraphicsProxyWidget</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_OBJECT</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">public</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">explicit</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Widget<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QGraphicsItem</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>parent<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">~</font>Widget<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_INVOKABLE</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>changeText<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">const</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QString</font><font color="#000000" style="line-height: 22px; ">&amp;</font><font color="#c0c0c0" style="line-height: 22px; "> </font>s<font color="#000000" style="line-height: 22px; ">);</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">signals</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>sendOnButton<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">private</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QPushButton</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>m_Btn<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QLabel</font><font color="#c0c0c0" style="line-height: 22px; ">      </font><font color="#000000" style="line-height: 22px; ">*</font>m_Label<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QWidget</font><font color="#c0c0c0" style="line-height: 22px; ">     </font><font color="#000000" style="line-height: 22px; ">*</font>m_MainWidget<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">};</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#endif</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">WIDGET_H</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="612" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="608" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="608" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//widget.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"widget.h"</font></font>
<font style="line-height: 22px; ">Widget<font color="#000000" style="line-height: 22px; ">::</font>Widget<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QGraphicsItem</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>parent<font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QGraphicsProxyWidget</font><font color="#000000" style="line-height: 22px; ">(</font>parent<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_MainWidget<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">new</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QWidget</font><font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_Btn<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">new</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QPushButton</font><font color="#000000" style="line-height: 22px; ">(</font>m_MainWidget<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_Label<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">new</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QLabel</font><font color="#000000" style="line-height: 22px; ">(</font>m_MainWidget<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_Btn<font color="#000000" style="line-height: 22px; ">-&gt;</font>setText<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"PushButton"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_Btn<font color="#000000" style="line-height: 22px; ">-&gt;</font>setGeometry<font color="#000000" style="line-height: 22px; ">(</font><font color="#000080" style="line-height: 22px; ">10</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">10</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">100</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">30</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_Label<font color="#000000" style="line-height: 22px; ">-&gt;</font>setGeometry<font color="#000000" style="line-height: 22px; ">(</font><font color="#000080" style="line-height: 22px; ">10</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">40</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">200</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">30</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#000000" style="line-height: 22px; ">::</font>connect<font color="#000000" style="line-height: 22px; ">(</font>m_Btn<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">SIGNAL</font><font color="#000000" style="line-height: 22px; ">(</font>clicked<font color="#000000" style="line-height: 22px; ">()),</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">this</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">SIGNAL</font><font color="#000000" style="line-height: 22px; ">(</font>sendOnButton<font color="#000000" style="line-height: 22px; ">()));</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">setWidget<font color="#000000" style="line-height: 22px; ">(</font>m_MainWidget<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font style="line-height: 22px; ">Widget<font color="#000000" style="line-height: 22px; ">::~</font>Widget<font color="#000000" style="line-height: 22px; ">()</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">delete</font><font color="#c0c0c0" style="line-height: 22px; "> </font>m_MainWidget<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Widget<font color="#000000" style="line-height: 22px; ">::</font>changeText<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">const</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QString</font><font color="#000000" style="line-height: 22px; ">&amp;</font><font color="#c0c0c0" style="line-height: 22px; "> </font>s<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_Label<font color="#000000" style="line-height: 22px; ">-&gt;</font>setText<font color="#000000" style="line-height: 22px; ">(</font>s<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qDebug<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">call</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">Widget::changeText"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="548" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="544" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="544" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">main.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtGui/QApplication&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeView&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeEngine&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeComponent&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeContext&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"widget.h"</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>main<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">char</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>argv<font color="#000000" style="line-height: 22px; ">[])</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QApplication</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">(</font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argv<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlRegisterType<font color="#000000" style="line-height: 22px; ">&lt;</font>Widget<font color="#000000" style="line-height: 22px; ">&gt;(</font><font color="#008000" style="line-height: 22px; ">"UIWidget"</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">1</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"Widget"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QDeclarativeView</font><font color="#c0c0c0" style="line-height: 22px; "> </font>qmlView<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>setSource<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QUrl</font><font color="#000000" style="line-height: 22px; ">::</font>fromLocalFile<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"../UICtest/UICtest.qml"</font><font color="#000000" style="line-height: 22px; ">));</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>show<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">.</font>exec<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="557" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="553" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="553" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">UICtest.qml</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Qt<font color="#c0c0c0" style="line-height: 22px; "> </font>4.7</font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; "> </font>UIWidget<font color="#c0c0c0" style="line-height: 22px; "> </font>1.0</font>
<font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Rectangle</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>640</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>480</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">color</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"black"</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Widget</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">id</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>uiwidget;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">x</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>100;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">y</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>100;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>400;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>100;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">关键在这里，当一个信号导出后他的相应的名字就是第<font style="line-height: 22px; ">1</font></font><font color="#008000" style="line-height: 22px; ">个字母大写，前面在加上<font style="line-height: 22px; ">on</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">例如</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">clicked</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">--</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">onClicked</font><font color="#c0c0c0" style="line-height: 22px; ">   </font><font color="#008000" style="line-height: 22px; ">colorchange</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">--onColorchange;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">onSendOnButton</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>{<font color="#c0c0c0" style="line-height: 22px; "> </font>uiwidget.changeText(textinput.text);<font color="#c0c0c0" style="line-height: 22px; "> </font>}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Rectangle</font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">x</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>100;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">y</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>20;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>400;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>30;<font color="#c0c0c0" style="line-height: 22px; ">  </font><font color="#800000" style="line-height: 22px; ">color</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"blue"</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">TextInput</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{<font color="#800000" style="line-height: 22px; ">id</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>textinput;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">anchors.fill</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>parent;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">color</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"white"</font><font color="#c0c0c0" style="line-height: 22px; "> </font>}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">}</font>
<font style="line-height: 22px; ">}</font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; ">说明：</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; "></font>这里实现的是当<font style="line-height: 22px; ">QPushButton</font>按钮按下后，获取<font style="line-height: 22px; ">QML</font>中<font style="line-height: 22px; ">TextInput</font>上的文本，</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; ">对<font style="line-height: 22px; ">QLabel</font>进行设置，关键点在于<font style="line-height: 22px; ">Widget</font>中的信号函数<font style="line-height: 22px; ">sendOnButton,&nbsp;</font>他导出后在<font style="line-height: 22px; ">QML</font>中</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; ">将引发的是<font style="line-height: 22px; ">onSendOnButton&nbsp;</font>只要在<font style="line-height: 22px; ">QML</font>中对这个编写处理就可以实现，具体看代码。</font></p></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152471.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 21:59 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152471.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML与c++交互学习笔记(六) 关于qt c++中创建对象，QML获取此对象数据问题  </title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152470.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 13:31:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152470.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152470.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152470.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152470.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152470.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #984e13; font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #f5f8ee; "><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">1.</font></font><font color="#000000" style="line-height: 22px; ">假设</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font><font color="#000000" style="line-height: 22px; ">1.</font></font><font color="#000000" style="line-height: 22px; ">在<font style="line-height: 22px; ">c++</font></font><font color="#000000" style="line-height: 22px; ">中创建一个</font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">Person</font></font><font color="#000000" style="line-height: 22px; ">的对象，</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font><font color="#000000" style="line-height: 22px; ">2.</font></font><font color="#000000" style="line-height: 22px; ">在</font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">QML</font></font><font color="#000000" style="line-height: 22px; ">中获取并显示数据</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font><font color="#000000" style="line-height: 22px; ">3.</font></font><font color="#000000" style="line-height: 22px; ">在</font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">c++</font></font><font color="#000000" style="line-height: 22px; ">中改变数据后，显示的数据能进行相应的改变</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font></font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font></font><font color="#000000" style="line-height: 22px; ">也就是说我们实际是在<font style="line-height: 22px; ">c++</font></font><font color="#000000" style="line-height: 22px; ">中<font style="line-height: 22px; ">new</font></font><font color="#000000" style="line-height: 22px; ">一个对象出来，而把这个对象的数据在<font style="line-height: 22px; ">QML</font></font><font color="#000000" style="line-height: 22px; ">里面进行显示</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; "></font><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">2.</font></font><font color="#000000" style="line-height: 22px; ">具体代码</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="613" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="609" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="609" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">person.h</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#ifndef</font><font color="#c0c0c0" style="line-height: 22px; "> </font>PERSON_H</font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#define</font><font color="#c0c0c0" style="line-height: 22px; "> </font>PERSON_H</font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QObject&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QDeclarativeListProperty&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QList&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QColor&gt;</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">class</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">:</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">public</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QObject</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_OBJECT</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_PROPERTY</font><font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QString</font><font color="#c0c0c0" style="line-height: 22px; "> </font>name<font color="#c0c0c0" style="line-height: 22px; "> </font>READ<font color="#c0c0c0" style="line-height: 22px; "> </font>getName<font color="#c0c0c0" style="line-height: 22px; "> </font>WRITE<font color="#c0c0c0" style="line-height: 22px; "> </font>setName<font color="#c0c0c0" style="line-height: 22px; "> </font>NOTIFY<font color="#c0c0c0" style="line-height: 22px; "> </font>sendNameChange<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_PROPERTY</font><font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>age<font color="#c0c0c0" style="line-height: 22px; "> </font>READ<font color="#c0c0c0" style="line-height: 22px; "> </font>getAge<font color="#c0c0c0" style="line-height: 22px; "> </font>WRITE<font color="#c0c0c0" style="line-height: 22px; "> </font>setAge<font color="#c0c0c0" style="line-height: 22px; "> </font>NOTIFY<font color="#c0c0c0" style="line-height: 22px; "> </font>sendAgeChange<font color="#000000" style="line-height: 22px; ">)</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">public</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">explicit</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>parent<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QString</font><font color="#c0c0c0" style="line-height: 22px; "> </font>getName<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">const</font><font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>setName<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">const</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QString</font><font color="#000000" style="line-height: 22px; ">&amp;</font><font color="#c0c0c0" style="line-height: 22px; "> </font>name<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>getAge<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>setAge<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>age<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">一个简单的函数<font style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">获取蓝色</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_INVOKABLE</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QColor</font><font color="#c0c0c0" style="line-height: 22px; "> </font>getColor<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">const</font><font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_INVOKABLE</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>changeNameAndAge<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">signals</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>sendNameChange<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>sendAgeChange<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">private</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QString</font><font color="#c0c0c0" style="line-height: 22px; ">     </font>m_Name<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; ">         </font>m_Age<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">};</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#endif</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">PERSON_H</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="372" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="368" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="368" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">person.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"person.h"</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; ">Person<font color="#000000" style="line-height: 22px; ">::</font>Person<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>parent<font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#000000" style="line-height: 22px; ">(</font>parent<font color="#000000" style="line-height: 22px; ">),</font><font color="#c0c0c0" style="line-height: 22px; "> </font>m_Name<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"unknow"</font><font color="#000000" style="line-height: 22px; ">),</font><font color="#c0c0c0" style="line-height: 22px; "> </font>m_Age<font color="#000000" style="line-height: 22px; ">(</font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QString</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>getName<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">const</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font>m_Name<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>setName<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">const</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QString</font><font color="#000000" style="line-height: 22px; ">&amp;</font><font color="#c0c0c0" style="line-height: 22px; "> </font>name<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_Name<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font>name<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">emit</font><font color="#c0c0c0" style="line-height: 22px; "> </font>sendNameChange<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>getAge<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font>m_Age<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>setAge<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>age<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_Age<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font>age<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">emit</font><font color="#c0c0c0" style="line-height: 22px; "> </font>sendAgeChange<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QColor</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>getColor<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">const</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QColor</font><font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">Qt</font><font color="#000000" style="line-height: 22px; ">::</font>blue<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>changeNameAndAge<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">setName<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"Luly"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">setAge<font color="#000000" style="line-height: 22px; ">(</font><font color="#000080" style="line-height: 22px; ">31</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="548" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="544" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="544" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">main.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtGui/QApplication&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeView&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeEngine&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeComponent&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeContext&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"person.h"</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>main<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">char</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>argv<font color="#000000" style="line-height: 22px; ">[])</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QApplication</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">(</font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argv<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">Person<font color="#c0c0c0" style="line-height: 22px; "> </font>tmpPerson<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">tmpPerson<font color="#000000" style="line-height: 22px; ">.</font>setName<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"Tom"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">tmpPerson<font color="#000000" style="line-height: 22px; ">.</font>setAge<font color="#000000" style="line-height: 22px; ">(</font><font color="#000080" style="line-height: 22px; ">25</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QDeclarativeView</font><font color="#c0c0c0" style="line-height: 22px; "> </font>qmlView<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>rootContext<font color="#000000" style="line-height: 22px; ">()-&gt;</font>setContextProperty<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"ps"</font><font color="#000000" style="line-height: 22px; ">,&amp;</font>tmpPerson<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>setSource<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QUrl</font><font color="#000000" style="line-height: 22px; ">::</font>fromLocalFile<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"../UICtest/UICtest.qml"</font><font color="#000000" style="line-height: 22px; ">));</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>show<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">.</font>exec<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="596" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="592" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="592" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">UICtest.qml</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Qt<font color="#c0c0c0" style="line-height: 22px; "> </font>4.7</font>
<font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Rectangle</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>640</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>480</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Text</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">text</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"Person</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">name:"</font><font color="#c0c0c0" style="line-height: 22px; "> </font>+<font color="#c0c0c0" style="line-height: 22px; "> </font>ps.name;<font color="#c0c0c0" style="line-height: 22px; "> </font>}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Text</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">y</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>20;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">text</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"Person</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">age:"</font><font color="#c0c0c0" style="line-height: 22px; "> </font>+<font color="#c0c0c0" style="line-height: 22px; "> </font>ps.age;<font color="#c0c0c0" style="line-height: 22px; "> </font>}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Rectangle</font>{<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">x</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>20;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">y</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>40;<font color="#c0c0c0" style="line-height: 22px; ">  </font><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>20;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>20;<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">color</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>ps.getColor();}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">MouseArea</font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">anchors.fill</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>parent;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">当鼠标按下后改变名字和年龄</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">onClicked</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>{<font color="#c0c0c0" style="line-height: 22px; "> </font>ps.changeNameAndAge();<font color="#c0c0c0" style="line-height: 22px; "> </font>}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">}</font>
<font style="line-height: 22px; ">}</font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">说明</span></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">：</span></font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font></font><font color="#000000" style="line-height: 22px; ">我们在<font style="line-height: 22px; ">c++</font></font><font color="#000000" style="line-height: 22px; ">中创建来一个对象，并且在把这个对象导出给<font style="line-height: 22px; ">QML</font></font><font color="#000000" style="line-height: 22px; ">调用用</font><font color="#000000" style="line-height: 22px; ">，我们设置来属性，<font style="line-height: 22px; ">QML</font></font><font color="#000000" style="line-height: 22px; ">中可以直接使用属性来进行赋值<font style="line-height: 22px; ">.</font></font></p></span><span class="Apple-style-span" style="color: #984e13; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 12px; line-height: normal; background-color: #f5f8ee; "><h3 class="title pre fs1" style="overflow-x: hidden; overflow-y: hidden; text-align: left; white-space: normal; word-wrap: break-word; word-break: break-all; font-size: 14px; margin-top: 30px; margin-right: 0px; margin-bottom: 20px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 24px; "><span class="tcnt" style="font-size: 20px; font-family: 微软雅黑, 黑体, Arial, Helvetica, sans-serif; "></span></h3></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152470.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 21:31 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152470.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML与c++交互学习笔记(五)   导出组合类</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152469.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 13:30:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152469.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152469.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152469.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152469.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152469.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1.导出Person类，并且一个PersonGroup类，PersonGroup类是Person的一个组2.具体导出过程1.通过属性来实现，具体的请看代码3.具体代码// person.h#ifndef PERSON_H#define PERSON_H#include &lt;QObject&gt;#include &lt;QDeclarativeListProperty&gt;...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2011/08/04/152469.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/152469.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 21:30 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152469.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML与c++交互学习笔记(四)  导出多类，并且有指针</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152468.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 13:29:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152468.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152468.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152468.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152468.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152468.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1.导出Person类，并且一个Job类，Job类包含一个Person的指针2.具体导出过程1.通过属性来实现，具体的请看代码3.具体代码// person.h#ifndef PERSON_H#define PERSON_H#include &lt;QObject&gt;#include &lt;QColor&gt;class Person : public QObject...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2011/08/04/152468.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/152468.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 21:29 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152468.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML与c++交互学习笔记(三)  导出C++类的成员属性</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152467.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 13:26:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152467.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152467.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152467.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152467.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152467.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #984e13; font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #f5f8ee; "><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; ">1.</font>导出<font style="line-height: 22px; ">Person</font>类中的属性</p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">2.</font></font><font color="#000000" style="line-height: 22px; ">具体导出过程</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font><font color="#000000" style="line-height: 22px; ">1.</font></font><font color="#000000" style="line-height: 22px; ">导出</font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">Person</font></font><font color="#000000" style="line-height: 22px; ">一个颜色属性</font><font color="#000000" style="line-height: 22px; ">，一个<font style="line-height: 22px; ">int</font></font><font color="#000000" style="line-height: 22px; ">属性</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#0000ff" style="line-height: 22px; "><font style="line-height: 22px; "></font>注意</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#0000ff" style="line-height: 22px; "><font style="line-height: 22px; ">1.&nbsp;</font>当需要实现属性变化其他引用到此属性的属性也跟着变化的情况的话，需要设置属性相应的信号</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#0000ff" style="line-height: 22px; "><font style="line-height: 22px; ">2.&nbsp;</font>设置属性的时候，使用的类型必须是已经导出到<font style="line-height: 22px; ">QML</font>中的类型</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">3.</font></font><font color="#000000" style="line-height: 22px; ">具体代码</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="701" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="697" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="697" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">person.h</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#ifndef</font><font color="#c0c0c0" style="line-height: 22px; "> </font>PERSON_H</font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#define</font><font color="#c0c0c0" style="line-height: 22px; "> </font>PERSON_H</font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QObject&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QColor&gt;</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">class</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">:</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">public</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QObject</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_OBJECT</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">设置设置属性的名字是</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">bgcolor</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">对应读取函数名字</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">bgColor</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">对应写函数名字</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">setBgColor</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">属性发生改变后发送信号</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">sendBgColorChange</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_PROPERTY</font><font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QColor</font><font color="#c0c0c0" style="line-height: 22px; "> </font>bgcolor<font color="#c0c0c0" style="line-height: 22px; "> </font>READ<font color="#c0c0c0" style="line-height: 22px; "> </font>getBgColor<font color="#c0c0c0" style="line-height: 22px; "> </font>WRITE<font color="#c0c0c0" style="line-height: 22px; "> </font>setBgColor<font color="#c0c0c0" style="line-height: 22px; "> </font>NOTIFY<font color="#c0c0c0" style="line-height: 22px; "> </font>sendBgColorChange<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">   </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">设置设置属性的名字是</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">count</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">   </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">对应读取函数名字</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">getCount</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">   </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">对应写函数名字</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">setCount</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">   </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">属性发生改变后发送信号</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">sendCountChange</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">   </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_PROPERTY</font><font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>count<font color="#c0c0c0" style="line-height: 22px; "> </font>READ<font color="#c0c0c0" style="line-height: 22px; "> </font>getCount<font color="#c0c0c0" style="line-height: 22px; "> </font>WRITE<font color="#c0c0c0" style="line-height: 22px; "> </font>setCount<font color="#c0c0c0" style="line-height: 22px; "> </font>NOTIFY<font color="#c0c0c0" style="line-height: 22px; "> </font>sendCountChange<font color="#000000" style="line-height: 22px; ">)</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">public</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">explicit</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>parent<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QColor</font><font color="#c0c0c0" style="line-height: 22px; "> </font>getBgColor<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">const</font><font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>setBgColor<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">const</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QColor</font><font color="#000000" style="line-height: 22px; ">&amp;</font><font color="#c0c0c0" style="line-height: 22px; "> </font>color<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>getCount<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>setCount<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>count<font color="#000000" style="line-height: 22px; ">);</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">signals</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>sendBgColorChange<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>sendCountChange<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">private</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QColor</font><font color="#c0c0c0" style="line-height: 22px; ">  </font>m_Color<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; ">     </font>m_Count<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">};</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#endif</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">PERSON_H</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="380" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="376" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="376" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">person.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"person.h"</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; ">Person<font color="#000000" style="line-height: 22px; ">::</font>Person<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>parent<font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#000000" style="line-height: 22px; ">(</font>parent<font color="#000000" style="line-height: 22px; ">),</font><font color="#c0c0c0" style="line-height: 22px; "> </font>m_Color<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"blue"</font><font color="#000000" style="line-height: 22px; ">),</font><font color="#c0c0c0" style="line-height: 22px; "> </font>m_Count<font color="#000000" style="line-height: 22px; ">(</font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QColor</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>getBgColor<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">const</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font>m_Color<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>setBgColor<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">const</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QColor</font><font color="#000000" style="line-height: 22px; ">&amp;</font><font color="#c0c0c0" style="line-height: 22px; "> </font>color<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_Color<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font>color<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">emit</font><font color="#c0c0c0" style="line-height: 22px; "> </font>sendBgColorChange<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>getCount<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font>m_Count<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//---------------------------------</font></font>
<font color="#008000" style="line-height: 22px; "><font style="line-height: 22px; ">//</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>setCount<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>count<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">m_Count<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font>count<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">emit</font><font color="#c0c0c0" style="line-height: 22px; "> </font>sendCountChange<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="548" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="544" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="544" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">main.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtGui/QApplication&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeView&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeEngine&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeComponent&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"person.h"</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>main<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">char</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>argv<font color="#000000" style="line-height: 22px; ">[])</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QApplication</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">(</font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argv<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlRegisterType<font color="#000000" style="line-height: 22px; ">&lt;</font>Person<font color="#000000" style="line-height: 22px; ">&gt;(</font><font color="#008000" style="line-height: 22px; ">"People"</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#000080" style="line-height: 22px; ">1</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#008000" style="line-height: 22px; ">"Person"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//qmlRegisterType&lt;Person&gt;();</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QDeclarativeView</font><font color="#c0c0c0" style="line-height: 22px; "> </font>qmlView<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>setSource<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QUrl</font><font color="#000000" style="line-height: 22px; ">::</font>fromLocalFile<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"../UICtest/UICtest.qml"</font><font color="#000000" style="line-height: 22px; ">));</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>show<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">.</font>exec<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="546" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="542" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="542" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">UICtest.qml</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Qt<font color="#c0c0c0" style="line-height: 22px; "> </font>4.7</font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; "> </font>People<font color="#c0c0c0" style="line-height: 22px; "> </font>1.0<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">//</font></font><font color="#008000" style="line-height: 22px; ">如果是<font style="line-height: 22px; ">qmlRegisterType&lt;Person&gt;();</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">导出就可以注释这条</font>
<font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Rectangle</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>640</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>480</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">color</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>per.bgcolor;</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Person</font>{<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">id</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>per;}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Text</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">id</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>textlabel;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">text</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"text</font><font color="#c0c0c0" style="line-height: 22px; ">  </font><font color="#008000" style="line-height: 22px; ">"</font><font color="#c0c0c0" style="line-height: 22px; "> </font>+<font color="#c0c0c0" style="line-height: 22px; "> </font>per.count;</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">MouseArea</font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">anchors.fill</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>parent;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">onClicked</font>:{</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">当鼠标按下后，由于属性上有信号，当属性发生改变后，</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">所有引用此属性的值的都相应的发生改变</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; ">per.bgcolor<font color="#c0c0c0" style="line-height: 22px; "> </font>=<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"red"</font>;</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; ">per.count<font color="#c0c0c0" style="line-height: 22px; "> </font>=<font color="#c0c0c0" style="line-height: 22px; "> </font>20;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; ">}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">}</font>
<font style="line-height: 22px; ">}</font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; ">说明：</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font></font><font color="#000000" style="line-height: 22px; ">在</font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">person</font></font><font color="#000000" style="line-height: 22px; ">类中，设置了两个属性<font style="line-height: 22px; ">bgcolor, count ,</font></font><font color="#000000" style="line-height: 22px; ">他们分别在发送改变后调用自己对应的信号</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; ">具体看源代码</font><font color="#000000" style="line-height: 22px; ">，</font><font color="#000000" style="line-height: 22px; ">这里是设置来矩形框的颜色，文本框中文本。</font></p></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152467.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 21:26 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152467.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML与c++交互学习笔记(二) 导出C++类的成员函数</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152466.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 13:25:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152466.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152466.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152466.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152466.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152466.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #984e13; font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #f5f8ee; "><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; ">1.</font>导出<font style="line-height: 22px; ">Person</font>类中的成员方法</p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">2.</font></font><font color="#000000" style="line-height: 22px; ">具体导出过程</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font></font><font color="#000000" style="line-height: 22px; ">导出的方法</font><font color="#000000" style="line-height: 22px; ">有</font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font><font color="#000000" style="line-height: 22px; ">1.</font></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">使用</span></font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">Q_INVOKABLE</font></font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font><font color="#000000" style="line-height: 22px; ">2.</font></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">使用&nbsp;</span></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">槽机制</span></font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">3.</font></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">具体代码</span></font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="324" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="320" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="320" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">person.h</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#ifndef</font><font color="#c0c0c0" style="line-height: 22px; "> </font>PERSON_H</font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#define</font><font color="#c0c0c0" style="line-height: 22px; "> </font>PERSON_H</font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QObject&gt;</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">class</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">:</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">public</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QObject</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_OBJECT</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">public</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">explicit</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>parent<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_INVOKABLE</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>FirstEcho<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">public</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">slots</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>SecondEcho<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">};</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#endif</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">PERSON_H</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="300" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="296" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="296" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">person.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"person.h"</font></font>
<font style="line-height: 22px; ">Person<font color="#000000" style="line-height: 22px; ">::</font>Person<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>parent<font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#000000" style="line-height: 22px; ">(</font>parent<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>FirstEcho<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">简简单单打印一句话</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qDebug<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"call</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">Person::FirstEcho"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">void</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">::</font>SecondEcho<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">void</font><font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qDebug<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"call</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">Person::SecondEcho"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="548" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="544" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="544" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">main.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtGui/QApplication&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeView&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeEngine&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeComponent&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"person.h"</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>main<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">char</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>argv<font color="#000000" style="line-height: 22px; ">[])</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QApplication</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">(</font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argv<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlRegisterType<font color="#000000" style="line-height: 22px; ">&lt;</font>Person<font color="#000000" style="line-height: 22px; ">&gt;(</font><font color="#008000" style="line-height: 22px; ">"People"</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#000080" style="line-height: 22px; ">1</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#008000" style="line-height: 22px; ">"Person"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//qmlRegisterType&lt;Person&gt;();</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QDeclarativeView</font><font color="#c0c0c0" style="line-height: 22px; "> </font>qmlView<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>setSource<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QUrl</font><font color="#000000" style="line-height: 22px; ">::</font>fromLocalFile<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"../UICtest/UICtest.qml"</font><font color="#000000" style="line-height: 22px; ">));</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>show<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">.</font>exec<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="546" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="542" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="542" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">UICtest.qml</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Qt<font color="#c0c0c0" style="line-height: 22px; "> </font>4.7</font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; "> </font>People<font color="#c0c0c0" style="line-height: 22px; "> </font>1.0<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">//</font></font><font color="#008000" style="line-height: 22px; ">如果是<font style="line-height: 22px; ">qmlRegisterType&lt;Person&gt;();</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">导出就可以注释这条</font>
<font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Rectangle</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>640</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>480</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Person</font>{<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800000" style="line-height: 22px; ">id</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>per;}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">MouseArea</font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">anchors.fill</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>parent;</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">onClicked</font>:{</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; ">per.FirstEcho();</font>
<font color="#c0c0c0" style="line-height: 22px; ">            </font><font style="line-height: 22px; ">per.SecondEcho();</font>
<font color="#c0c0c0" style="line-height: 22px; ">        </font><font style="line-height: 22px; ">}</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">}</font>
<font style="line-height: 22px; ">}</font></pre></td></tr></tbody></table><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">说明</span><font style="line-height: 22px; ">:</font></font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; "></font></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">这里导出了两个函数分别是</span></font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">FirstEcho&nbsp;</font></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">和</span></font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">S</font><font color="#000000" style="line-height: 22px; ">econdEcho&nbsp;</font></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">两个函数</span></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">，这两个函数本别是使用</span></font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">FirstEcho</font></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">使用使用&nbsp;</span></font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">Q_INVOKABLE</font></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">导出，</span></font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">S</font><font color="#000000" style="line-height: 22px; ">econdEcho</font></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">直接使用槽</span></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">。</span></font></p><p align="LEFT" style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">调用函数在控制台输出一些信息</span></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">，这里是在鼠标点击界面后出发的</span></font><font color="#000000" style="line-height: 22px; "><span style="line-height: 22px; ">。</span></font></p></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152466.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 21:25 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152466.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML与c++交互学习笔记(一) </title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152465.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 13:21:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152465.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152465.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152465.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152465.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152465.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #984e13; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 12px; line-height: normal; background-color: #f5f8ee; "><div class="bct fc05 fc11 nbw-blog ztag js-fs2" style="line-height: 22px; font-size: 14px; text-align: left; word-wrap: break-word; color: #984e13; margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; overflow-y: hidden; "><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">关于导出<font style="line-height: 22px; ">C++</font>的学习<font style="line-height: 22px; "></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">说明，主要是对<font style="line-height: 22px; ">QT</font>的文档内例子进行的一些分别解说，希望更容易的理解<font style="line-height: 22px; "></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; ">C++</font>导出到<font style="line-height: 22px; ">QML</font>的过程。</p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; ">1.</font>导出一个简单的类<font style="line-height: 22px; ">Person</font></p><font style="line-height: 22px; "></font><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; ">2.</font>具体导出过程<font style="line-height: 22px; "></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 假设我们要导出一个<font style="line-height: 22px; ">Person</font>类，<font style="line-height: 22px; "></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="line-height: 22px; "><strong style="line-height: 22px; ">A</strong>&nbsp;</font>那么就要考虑如何的一个类他才可以导出呢？<font style="line-height: 22px; "></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 他需要符合一定的条件<font style="line-height: 22px; "></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="line-height: 22px; ">1.</font>继承自<font style="line-height: 22px; ">QObject</font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="line-height: 22px; ">2.</font>有默认构造函数<font style="line-height: 22px; "></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="line-height: 22px; "><strong style="line-height: 22px; ">B</strong>&nbsp;</font>如何导出呢？<font style="line-height: 22px; "></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 通过一个函数<font style="line-height: 22px; "></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="line-height: 22px; ">int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)</font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="line-height: 22px; ">int qmlRegisterType()</font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">3.具体的例子</p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="324" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="320" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="320" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">person.h</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#ifndef</font><font color="#c0c0c0" style="line-height: 22px; "> </font>PERSON_H</font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#define</font><font color="#c0c0c0" style="line-height: 22px; "> </font>PERSON_H</font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QObject&gt;</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">class</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">:</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">public</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#800080" style="line-height: 22px; ">QObject</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Q_OBJECT</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">public</font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">explicit</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Person<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>parent<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">=</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">};</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#endif</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">PERSON_H</font></font></pre></td></tr></tbody></table><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font style="line-height: 22px; "></font></p><table width="275" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="271" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="271" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">person.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"person.h"</font></font>
<font style="line-height: 22px; ">Person<font color="#000000" style="line-height: 22px; ">::</font>Person<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>parent<font color="#000000" style="line-height: 22px; ">)</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">:</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QObject</font><font color="#000000" style="line-height: 22px; ">(</font>parent<font color="#000000" style="line-height: 22px; ">)</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="548" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="544" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="544" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">main.cpp</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtGui/QApplication&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeView&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeEngine&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">&lt;QtDeclarative/QDeclarativeComponent&gt;</font></font>
<font style="line-height: 22px; "><font color="#000080" style="line-height: 22px; ">#include</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">"person.h"</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>main<font color="#000000" style="line-height: 22px; ">(</font><font color="#808000" style="line-height: 22px; ">int</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#808000" style="line-height: 22px; ">char</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#000000" style="line-height: 22px; ">*</font>argv<font color="#000000" style="line-height: 22px; ">[])</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">{</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QApplication</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">(</font>argc<font color="#000000" style="line-height: 22px; ">,</font><font color="#c0c0c0" style="line-height: 22px; "> </font>argv<font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlRegisterType<font color="#000000" style="line-height: 22px; ">&lt;</font>Person<font color="#000000" style="line-height: 22px; ">&gt;(</font><font color="#008000" style="line-height: 22px; ">"People"</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#000080" style="line-height: 22px; ">1</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#008000" style="line-height: 22px; ">"Person"</font><font color="#000000" style="line-height: 22px; ">);</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//qmlRegisterType&lt;Person&gt;();</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">QDeclarativeView</font><font color="#c0c0c0" style="line-height: 22px; "> </font>qmlView<font color="#000000" style="line-height: 22px; ">;</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>setSource<font color="#000000" style="line-height: 22px; ">(</font><font color="#800080" style="line-height: 22px; ">QUrl</font><font color="#000000" style="line-height: 22px; ">::</font>fromLocalFile<font color="#000000" style="line-height: 22px; ">(</font><font color="#008000" style="line-height: 22px; ">"../UICtest/UICtest.qml"</font><font color="#000000" style="line-height: 22px; ">));</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; ">qmlView<font color="#000000" style="line-height: 22px; ">.</font>show<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">return</font><font color="#c0c0c0" style="line-height: 22px; "> </font>a<font color="#000000" style="line-height: 22px; ">.</font>exec<font color="#000000" style="line-height: 22px; ">();</font></font>
<font color="#000000" style="line-height: 22px; "><font style="line-height: 22px; ">}</font></font></pre></td></tr></tbody></table><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 22px; " /></p><table width="546" cellpadding="2" cellspacing="0" style="line-height: 22px; "><colgroup style="line-height: 22px; "><col width="542" style="line-height: 22px; "></colgroup><tbody style="line-height: 22px; "><tr style="line-height: 22px; "><td width="542" style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><pre style="line-height: 22px; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; padding-top: 0cm; padding-right: 0cm; padding-bottom: 0cm; padding-left: 0cm; "><font style="line-height: 22px; "><font color="#008000" style="line-height: 22px; ">//</font><font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">UICtest.qml</font></font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; "> </font>Qt<font color="#c0c0c0" style="line-height: 22px; "> </font>4.7</font>
<font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; "> </font>People<font color="#c0c0c0" style="line-height: 22px; "> </font>1.0<font color="#c0c0c0" style="line-height: 22px; "> </font><font color="#008000" style="line-height: 22px; ">//</font></font><font color="#008000" style="line-height: 22px; ">如果是<font style="line-height: 22px; ">qmlRegisterType&lt;Person&gt;();</font><font color="#c0c0c0" style="line-height: 22px; "> </font></font><font color="#008000" style="line-height: 22px; ">导出就可以注释这条</font>
<font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Rectangle</font><font color="#c0c0c0" style="line-height: 22px; "> </font>{</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">width</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>640</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800000" style="line-height: 22px; ">height</font>:<font color="#c0c0c0" style="line-height: 22px; "> </font>480</font>
<font color="#c0c0c0" style="line-height: 22px; ">    </font><font style="line-height: 22px; "><font color="#800080" style="line-height: 22px; ">Person</font>{}</font>
<font style="line-height: 22px; ">}</font></pre></td></tr></tbody></table><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">说明<font style="line-height: 22px; ">:</font>我们通过<font style="line-height: 22px; ">qmlRegisterType<font color="#000000" style="line-height: 22px; ">&lt;</font>Person<font color="#000000" style="line-height: 22px; ">&gt;(</font><font color="#008000" style="line-height: 22px; ">"People"</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#000080" style="line-height: 22px; ">1</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#000080" style="line-height: 22px; ">0</font><font color="#000000" style="line-height: 22px; ">,</font><font color="#008000" style="line-height: 22px; ">"Person"</font><font color="#000000" style="line-height: 22px; ">);</font></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; ">向</font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">QML</font></font><font color="#000000" style="line-height: 22px; ">中导出</font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">Person</font></font><font color="#000000" style="line-height: 22px; ">类</font><font color="#000000" style="line-height: 22px; ">，这个类在<font style="line-height: 22px; ">People</font></font><font color="#000000" style="line-height: 22px; ">包中</font><font color="#000000" style="line-height: 22px; ">，在<font style="line-height: 22px; ">QML</font></font><font color="#000000" style="line-height: 22px; ">中需要使用</font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">Person</font></font><font color="#000000" style="line-height: 22px; ">类的</font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; ">话就必须包含</font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">People</font></font><font color="#000000" style="line-height: 22px; ">包</font><font color="#000000" style="line-height: 22px; ">，通过</font><font style="line-height: 22px; "><font color="#808000" style="line-height: 22px; ">import</font><font color="#c0c0c0" style="line-height: 22px; ">&nbsp;</font><font color="#000000" style="line-height: 22px; ">People</font><font color="#c0c0c0" style="line-height: 22px; ">&nbsp;</font><font color="#000000" style="line-height: 22px; ">1.0</font></font><font color="#000000" style="line-height: 22px; ">来包含</font><font color="#000000" style="line-height: 22px; ">，之后就可以使用</font><font style="line-height: 22px; "><font color="#000000" style="line-height: 22px; ">Person</font></font></p><p style="margin-bottom: 0cm; line-height: 22px; margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font color="#000000" style="line-height: 22px; ">创建对象使用来</font><font color="#000000" style="line-height: 22px; ">。</font></p></div><div></div><div></div><div><div><div class="wumii-hook"></div></div></div><div class="nbw-act tbar fc03 clearfix" style="zoom: 1; margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; text-align: right; color: #839432; line-height: 20px; "><div style="height: 24px; line-height: 24px; "><div class="pleft rdif" style="float: left; line-height: 24px; height: 24px; "></div></div></div></span><span style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #f5f8ee; line-height: 22px;"><div tbar="" fc03=""  clearfix"="" style="zoom: 1; margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; text-align: right; "><div style="text-align: left; height: 24px; "><font class="Apple-style-span" color="#984e13"><br /></font></div></div></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152465.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 21:21 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152465.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于QML中调用qt类中的信号，槽，成员函数,属性做记录</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152464.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 13:19:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152464.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152464.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152464.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152464.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152464.html</trackback:ping><description><![CDATA[<span style="color: #984e13; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 14px; line-height: 22px; background-color: #f5f8ee; ">废话不多说直接上代码<br style="line-height: 22px; " />(<span style="line-height: 22px; font-size: 10.5pt; font-family: 'Times New Roman'; ">(xp</span><span style="line-height: 22px; font-size: 10.5pt; font-family: 宋体; ">下</span><span style="line-height: 22px; font-size: 10.5pt; font-family: 'Times New Roman'; ">qt4.7 sdk)</span>&nbsp;出现情况是，当一个类<span style="line-height: 22px; font-size: 10.5pt; font-family: 宋体; ">在直接写在一个.h文件上后，在QML中调用会挂掉，我这里出现是在我调用的到处函数是获取一个QString的时候，但是把类分别写成.h和.cpp后，没有出现此 情况</span><span style="line-height: 22px; font-size: 10.5pt; font-family: 宋体; ">，不知道具体的原因</span>）<br style="line-height: 22px; " /><span style="line-height: 22px; color: #008000; ">//</span>&nbsp;<span style="line-height: 22px; color: #008000; ">main.cpp</span><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #808000; ">int</span> main<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">int</span> argc<span style="line-height: 22px; color: #000000; ">,</span> <span style="line-height: 22px; color: #808000; ">char</span> <span style="line-height: 22px; color: #000000; ">*</span>argv<span style="line-height: 22px; color: #000000; ">[])</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">{</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">QApplication</span> app<span style="line-height: 22px; color: #000000; ">(</span>argc<span style="line-height: 22px; color: #000000; ">,</span> argv<span style="line-height: 22px; color: #000000; ">);</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">QDeclarativeView</span> view<span style="line-height: 22px; color: #000000; ">;</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> view<span style="line-height: 22px; color: #000000; ">.</span>rootContext<span style="line-height: 22px; color: #000000; ">()-&gt;</span>setContextProperty<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #008000; ">"ls"</span><span style="line-height: 22px; color: #000000; ">,</span><span style="line-height: 22px; color: #808000; ">new</span> LS<span style="line-height: 22px; color: #000000; ">);</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> view<span style="line-height: 22px; color: #000000; ">.</span>setSource<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #800080; ">QUrl</span><span style="line-height: 22px; color: #000000; ">::</span>fromLocalFile<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #008000; ">"../QMLAPP/QMLtest.qml"</span><span style="line-height: 22px; color: #000000; ">));</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> view<span style="line-height: 22px; color: #000000; ">.</span>show<span style="line-height: 22px; color: #000000; ">();</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #808000; ">return</span> app<span style="line-height: 22px; color: #000000; ">.</span>exec<span style="line-height: 22px; color: #000000; ">();</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">}</span></pre>// LS.h<br style="line-height: 22px; " /><span style="line-height: 22px; color: #000080; ">#ifndef</span>&nbsp;LS_H<pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #000080; ">#define</span> LS_H</pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #000080; ">#include</span> <span style="line-height: 22px; color: #008000; ">&lt;QObject&gt;</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #000080; ">#include</span> <span style="line-height: 22px; color: #008000; ">&lt;QColor&gt;</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #808000; ">class</span> LS <span style="line-height: 22px; color: #000000; ">:</span> <span style="line-height: 22px; color: #808000; ">public</span> <span style="line-height: 22px; color: #800080; ">QObject</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #000000; ">{</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">Q_OBJECT</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">Q_PROPERTY</span><span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #800080; ">QColor</span> color READ getColor WRITE setColor NOTIFY colorChange<span style="line-height: 22px; color: #000000; ">)</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #808000; ">public</span><span style="line-height: 22px; color: #000000; ">:</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> LS<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #800080; ">QObject</span> <span style="line-height: 22px; color: #000000; ">*</span>parent <span style="line-height: 22px; color: #000000; ">=</span> <span style="line-height: 22px; color: #000080; ">0</span><span style="line-height: 22px; color: #000000; ">);</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">~</span>LS<span style="line-height: 22px; color: #000000; ">();</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #008000; ">//</span> <span style="line-height: 22px; color: #008000; ">Q_INVOKABLE</span> <span style="line-height: 22px; color: #008000; ">用于导出函数，让qml能使用</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">Q_INVOKABLE</span> <span style="line-height: 22px; color: #800080; ">QString</span> getText<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">void</span><span style="line-height: 22px; color: #000000; ">)</span> <span style="line-height: 22px; color: #808000; ">const</span><span style="line-height: 22px; color: #000000; ">;</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #008000; ">//</span> <span style="line-height: 22px; color: #008000; ">用于属性</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">QColor</span> getColor<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">void</span><span style="line-height: 22px; color: #000000; ">)</span> <span style="line-height: 22px; color: #808000; ">const</span><span style="line-height: 22px; color: #000000; ">;</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #808000; ">void</span> setColor<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">const</span> <span style="line-height: 22px; color: #800080; ">QColor</span> <span style="line-height: 22px; color: #000000; ">&amp;</span>c<span style="line-height: 22px; color: #000000; ">);</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #808000; ">signals</span><span style="line-height: 22px; color: #000000; ">:</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #808000; ">void</span> sendMsg<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">const</span> <span style="line-height: 22px; color: #800080; ">QString</span> <span style="line-height: 22px; color: #000000; ">&amp;</span>s<span style="line-height: 22px; color: #000000; ">);</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #008000; ">//</span> <span style="line-height: 22px; color: #008000; ">用于属性</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #808000; ">void</span> colorChange<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">void</span><span style="line-height: 22px; color: #000000; ">);</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #808000; ">public</span> <span style="line-height: 22px; color: #808000; ">slots</span><span style="line-height: 22px; color: #000000; ">:</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #808000; ">void</span> echoMsg<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">const</span> <span style="line-height: 22px; color: #800080; ">QString</span> <span style="line-height: 22px; color: #000000; ">&amp;</span>s<span style="line-height: 22px; color: #000000; ">);</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #808000; ">private</span><span style="line-height: 22px; color: #000000; ">:</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">QString</span> m_str<span style="line-height: 22px; color: #000000; ">;</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">QColor</span> m_Color<span style="line-height: 22px; color: #000000; ">;</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #000000; ">};</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #000080; ">#endif</span> <span style="line-height: 22px; color: #008000; ">//</span> <span style="line-height: 22px; color: #008000; ">LS_H</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><br style="line-height: 22px; " /></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><br style="line-height: 22px; " />//LS.cpp<br style="line-height: 22px; " /></pre><span style="line-height: 22px; color: #000080; ">#include</span>&nbsp;<span style="line-height: 22px; color: #008000; ">"LS.h"</span><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> LS<span style="line-height: 22px; color: #000000; ">::</span>LS<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #800080; ">QObject</span> <span style="line-height: 22px; color: #000000; ">*</span>parent<span style="line-height: 22px; color: #000000; ">)</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">:</span><span style="line-height: 22px; color: #800080; ">QObject</span><span style="line-height: 22px; color: #000000; ">(</span>parent<span style="line-height: 22px; color: #000000; ">),</span>m_str<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #008000; ">"I</span> <span style="line-height: 22px; color: #008000; ">am</span> <span style="line-height: 22px; color: #008000; ">LS</span> <span style="line-height: 22px; color: #008000; ">class"</span><span style="line-height: 22px; color: #000000; ">),</span>m_Color<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #800080; ">Qt</span><span style="line-height: 22px; color: #000000; ">::</span>blue<span style="line-height: 22px; color: #000000; ">)</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">{</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">QObject</span><span style="line-height: 22px; color: #000000; ">::</span>connect<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">this</span><span style="line-height: 22px; color: #000000; ">,</span> <span style="line-height: 22px; color: #808000; ">SIGNAL</span><span style="line-height: 22px; color: #000000; ">(</span>sendMsg<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #800080; ">QString</span><span style="line-height: 22px; color: #000000; ">)),</span> <span style="line-height: 22px; color: #808000; ">this</span><span style="line-height: 22px; color: #000000; ">,</span> <span style="line-height: 22px; color: #808000; ">SLOT</span><span style="line-height: 22px; color: #000000; ">(</span>echoMsg<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #800080; ">QString</span><span style="line-height: 22px; color: #000000; ">)));</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">}</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> LS<span style="line-height: 22px; color: #000000; ">::~</span>LS<span style="line-height: 22px; color: #000000; ">(){}</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">QString</span> LS<span style="line-height: 22px; color: #000000; ">::</span>getText<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">void</span><span style="line-height: 22px; color: #000000; ">)</span> <span style="line-height: 22px; color: #808000; ">const</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">{</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #808000; ">return</span> m_str<span style="line-height: 22px; color: #000000; ">;</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">}</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #008000; ">//</span> <span style="line-height: 22px; color: #008000; ">用于属性</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #800080; ">QColor</span> LS<span style="line-height: 22px; color: #000000; ">::</span>getColor<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">void</span><span style="line-height: 22px; color: #000000; ">)</span> <span style="line-height: 22px; color: #808000; ">const</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">{</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #808000; ">return</span> m_Color<span style="line-height: 22px; color: #000000; ">;</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">}</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #808000; ">void</span> LS<span style="line-height: 22px; color: #000000; ">::</span>setColor<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">const</span> <span style="line-height: 22px; color: #800080; ">QColor</span> <span style="line-height: 22px; color: #000000; ">&amp;</span>c<span style="line-height: 22px; color: #000000; ">)</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">{</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> m_Color <span style="line-height: 22px; color: #000000; ">=</span> c<span style="line-height: 22px; color: #000000; ">;</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">}</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #808000; ">void</span> LS<span style="line-height: 22px; color: #000000; ">::</span>echoMsg<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #808000; ">const</span> <span style="line-height: 22px; color: #800080; ">QString</span> <span style="line-height: 22px; color: #000000; ">&amp;</span>s<span style="line-height: 22px; color: #000000; ">)</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">{</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> qDebug<span style="line-height: 22px; color: #000000; ">(</span><span style="line-height: 22px; color: #008000; ">"</span> <span style="line-height: 22px; color: #008000; ">%s</span> <span style="line-height: 22px; color: #008000; ">"</span><span style="line-height: 22px; color: #000000; ">,</span> s<span style="line-height: 22px; color: #000000; ">.</span>toLocal8Bit<span style="line-height: 22px; color: #000000; ">().</span>data<span style="line-height: 22px; color: #000000; ">());</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "> <span style="line-height: 22px; color: #000000; ">}</span></pre><pre style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; "><span style="line-height: 22px; color: #008000; ">//----------------------------------------------------------------------</span><br style="line-height: 22px; " /><span style="line-height: 22px; color: #008000; ">//</span> <span style="line-height: 22px; color: #008000; ">QMLtest.qml</span><br style="line-height: 22px; " /><span style="line-height: 22px; color: #800080; ">Rectangle</span>{<br style="line-height: 22px; " /> <span style="line-height: 22px; color: #800000; ">id</span>: mainrect<br style="line-height: 22px; " /> <span style="line-height: 22px; color: #800000; ">width</span>: 400; <span style="line-height: 22px; color: #800000; ">height</span>: 300;<br style="line-height: 22px; " /> <span style="line-height: 22px; color: #800000; ">color</span>: ls.color;<br style="line-height: 22px; " /> <span style="line-height: 22px; color: #800080; ">Text</span> {<br style="line-height: 22px; " /> <span style="line-height: 22px; color: #800000; ">id</span>: tls;<br style="line-height: 22px; " /> <span style="line-height: 22px; color: #800000; ">text</span>: <span style="line-height: 22px; color: #008000; ">"click</span> <span style="line-height: 22px; color: #008000; ">this"</span><br style="line-height: 22px; " /> }<br style="line-height: 22px; " /><br style="line-height: 22px; " /> <span style="line-height: 22px; color: #800080; ">MouseArea</span>{<br style="line-height: 22px; " /> <span style="line-height: 22px; color: #800000; ">anchors.fill</span>: parent;<br style="line-height: 22px; " /> <span style="line-height: 22px; color: #800000; ">onClicked</span>: {<br style="line-height: 22px; " /> tls.text = ls.getText();<br style="line-height: 22px; " /> ls.sendMsg(<span style="line-height: 22px; color: #008000; ">"</span> <span style="line-height: 22px; color: #008000; ">ok</span> <span style="line-height: 22px; color: #008000; ">"</span>);<br style="line-height: 22px; " /> }<br style="line-height: 22px; " /> }<br style="line-height: 22px; " /><br style="line-height: 22px; " />}</pre></span><img src ="http://www.cppblog.com/lauer3912/aggbug/152464.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 21:19 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152464.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Quick3D 学习文档  (QML) 转载</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152463.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 13:14:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152463.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152463.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152463.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152463.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152463.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 一.介绍quick3d是把qt3d部分以插件的形式导出，在QML中通过包含的形式来进行使用的。quick3d部分，使用的包含有import Qt3D 1.0import Qt3D.Shapes 1.0Import Qt3D&nbsp;是包含主要的一些Qt3D模块，而Qt3D.Shapes&nbsp;包含的是一些立方体，球体，圆柱体等的信息，方便使用各种简单模型。二.具体的说明(这里没有按照原来...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2011/08/04/152463.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/152463.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 21:14 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152463.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QML 基本内容介绍</title><link>http://www.cppblog.com/lauer3912/archive/2011/08/04/152460.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 04 Aug 2011 12:06:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/08/04/152460.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/152460.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/08/04/152460.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/152460.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/152460.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1.&nbsp;介绍QML是一种描述语言，主要是对界面效果等的一种描述，它可以结合javaScript来进行更复杂的效果及逻辑实现。比如做个游戏，实现一些更有趣的功能等2.&nbsp;简单的例子import&nbsp;Qt&nbsp;4.7Rectangle&nbsp;{width:&nbsp;200height:&nbsp;200color:&nbsp;"blue"}代码是绘制一个蓝色的矩形，宽...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2011/08/04/152460.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/152460.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-08-04 20:06 <a href="http://www.cppblog.com/lauer3912/archive/2011/08/04/152460.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>