<ul> <li> <div align="left">清楚Qt的都清楚信号的槽,它无比的强大,怎么强大呢这里就不解释了。<a href="http://www.ibm.com/developerworks/cn/linux/guitoolkit/qt/signal-slot/" target="_blank">信号与槽机制介绍</a></div> </li> <li> <div align="left">当然都是Qt的东西,QML也可以用信号和槽,现在介绍一下他们通过信号和操怎么互传数据</div> </li> <li> <div align="left">继承QDeclarativeView</div> </li> <li> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:10c9203c-57c5-48c4-a81a-d57ffd630a1e" class="wlWriterEditableSmartContent"><pre class="brush: cpp; gutter: false; first-line: 1; tab-size: 4; toolbar: false; width: 400px; height: 58px;" style=" width: 400px; height: 58px;overflow: auto;">QObject *rootObject = reinterpret_cast<QObject*>(this->rootObject());</pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div> </li>
<li>得到rootObject,返回的是一个QGraphicsObject的值,这里的把他强制转换成QObject才能使用信号和槽。 </li> </ul>
<h2>接收QML信号</h2>
<ul> <h2></h2> </ul>
<blockquote> <p>QML内容</p> </blockquote>
<ul> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:836eca43-a252-470a-8833-4062530a7893" class="wlWriterEditableSmartContent"><pre class="brush: css; gutter: false; first-line: 1; tab-size: 4; toolbar: false; width: 400px; height: 288px;" style=" width: 400px; height: 288px;overflow: auto;">import QtQuick 2.0
Rectangle { id:roots width: 100 height: 62 color:"#cccccc" signal singalText1(string valueStr); Text{ id:text1 text:"hello word 2" } MouseArea{ onClicked:roots.singalText1(text1.text); } }</pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
</ul>
<ul></ul>
<ul></ul>
<p></p>
<blockquote> <p>接收Qml的信号</p> </blockquote>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:efc5367f-113e-46a7-83f0-4bb2e8073f74" class="wlWriterEditableSmartContent"><pre class="brush: cpp; gutter: false; first-line: 1; tab-size: 4; toolbar: false; width: 400px; height: 70px;" style=" width: 400px; height: 70px;overflow: auto;">connect(rootObject, SIGNAL(singalText1(QString )),this,SLOT(slotsQML(QString )));</pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
<h2>向QML传值</h2>
<blockquote> <p>QML内容</p> </blockquote>
<p></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:4e05bf39-8a81-45ae-9e46-d98472b0f7d7" class="wlWriterEditableSmartContent"><pre class="brush: xml; gutter: false; first-line: 1; tab-size: 4; toolbar: false; width: 400px; height: 108px;" style=" width: 400px; height: 108px;overflow: auto;">import QtQuick 2.0
Rectangle { id:roots width: 100 height: 62 color:"#cccccc" signal singalText1(string valueStr); function slotsStr(value){ text1.text = value }
Text{
id:text1
text:"hello word 2"
}
MouseArea{
onClicked:roots.singalText1(text1.text);
}
}</pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
<p></p>
<blockquote> <p>Qt</p> </blockquote>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:512f7353-b9ec-4067-b9fc-bdcba084baf9" class="wlWriterEditableSmartContent"><pre class="brush: cpp; gutter: false; first-line: 1; tab-size: 4; toolbar: false; width: 400px; height: 180px;" style=" width: 400px; height: 180px;overflow: auto;">void setText(QString value){ emit singalSetText(value) } connect(this,SIGNAL(singalSetText(QVariant)),rootObject,SLOT(boatMark(QVariant)));</pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>