<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Not getting Key and mouse events.]]></title><description><![CDATA[<p dir="auto">Hi All,</p>
<p dir="auto">I am trying to build one sample application using QML+JavaScript and CPP.<br />
I an facing problem while running the application.</p>
<p dir="auto">My application does not receive any keyboard/key events also I am not getting proper mouse click events.<br />
I have one QML file in which i have two rectangles where I have key and mouse event listener code:</p>
<p dir="auto">@<br />
Rectangle<br />
{<br />
id: keyRect<br />
focus:true;<br />
color: "black"<br />
Keys.onPressed:<br />
{<br />
console.log("Keys.onPressed\n");<br />
}<br />
}</p>
<p dir="auto">Rectangle<br />
{<br />
id: mouseRect;<br />
focus:true;<br />
color: "blue"<br />
MouseArea<br />
{<br />
anchors.fill: parent<br />
acceptedButtons: Qt.LeftButton;<br />
onReleased:<br />
{<br />
console.log("Mouse Clicked\n");<br />
}<br />
}<br />
}<br />
@</p>
<p dir="auto">I am not getting any events in key listener "Keys.onPressed:" and for mouse event whenever I move mouse pointer on the mouse rectangle (without clicking) I get print "Mouse Clicked" print.</p>
<p dir="auto">This is my main.cpp file from where i am launching the first qml file which will start the application.</p>
<p dir="auto">@#include &lt;QApplication&gt;<br />
#include &lt;QtDeclarative&gt;<br />
#include &lt;QDeclarativeView&gt;<br />
#include &lt;QVariant&gt;</p>
<p dir="auto">QT_USE_NAMESPACE</p>
<p dir="auto">void* qmlMain(int argc, char *argv[])<br />
{<br />
QApplication app(argc, argv);</p>
<pre><code>QDeclarativeView view;
view.setSource(QUrl::fromLocalFile&amp;#40;"appEntry.qml"&amp;#41;);

app.setApplicationName("TestApp");
app.setOrganizationName("Test");
app.setOrganizationDomain("TestApp.com");

view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
view.show();

app.exec();

return 0;
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto">Do i need to add anything else in above code to make it work.<br />
When i run this QML file with QML viewer it is working perfectly I am getting all the events.</p>
<p dir="auto">Thanks in advance.</p>
]]></description><link>https://forum.qt.io/topic/10207/not-getting-key-and-mouse-events</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 07:02:25 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/10207.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 07 Oct 2011 12:22:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Not getting Key and mouse events. on Sun, 20 May 2012 15:49:29 GMT]]></title><description><![CDATA[<p dir="auto">Did you use sendEvent with keyEvent ?</p>
]]></description><link>https://forum.qt.io/post/125715</link><guid isPermaLink="true">https://forum.qt.io/post/125715</guid><dc:creator><![CDATA[aabc]]></dc:creator><pubDate>Sun, 20 May 2012 15:49:29 GMT</pubDate></item><item><title><![CDATA[Reply to Not getting Key and mouse events. on Sat, 08 Oct 2011 09:55:08 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">you can try the below line.</p>
<p dir="auto">Component.onCompleted:{ keyRect.focus = true }</p>
]]></description><link>https://forum.qt.io/post/112572</link><guid isPermaLink="true">https://forum.qt.io/post/112572</guid><dc:creator><![CDATA[zanes]]></dc:creator><pubDate>Sat, 08 Oct 2011 09:55:08 GMT</pubDate></item></channel></rss>